Python for mac 中包安裝管理;Mac Python管理虛擬環境軟件安裝;Python包管理工具;python多版本管理(MacOS)php
持續更新中...html
#去查看要更新pip目前的版本 $ pip -V # for Python 2 $ pip3 -V # for Python 3
#檢查完後,要升級對應的版本 #第一種,若是失敗,嘗試第二種 $pip install --upgrade pip # for Python2 $pip3 install --upgrade pip # for Python3 #第二種 $ sudo easy_install --upgrade pip $ sudo easy_install --upgrade six #能夠不實用這條
目錄html5
前言java
一 管理虛擬環境軟件node
1.1 Mac Python管理虛擬環境軟件安裝-Pyenv具體的流程python
1.2 Mac Python管理虛擬環境軟件安裝-Anaconda具體的流程mysql
1.3 Mac Python管理虛擬環境軟件安裝-pip具體的流程linux
二 探索的原由git
2.1 具體的問題(報錯)程序員
2.2 先檢查Python的安裝與路徑
2.3 安裝包——Numpy
2.4 安裝包——matplotlib
2.5 安裝包——scipy
2.6 安裝pandas
2.7 安裝TensorFlow
前言
你們要在開發中,使用多個python版本的,強烈建議使用安裝管理器和工具管理虛擬環境,否則就會出現如下一系列報錯。所以會教你如何安裝Python的 pandas等各種包。
安裝brew,安裝教程。咱們經過brew能夠快捷方便的下載咱們須要的各種軟件,包括pyenv,Anaconda,virtualenv(虛擬環境)等。咱們經過如下途徑來完成python包的管理:
1. Anaconda:安裝pandas、Python和SciPy最簡單的方式是用Anaconda。Anaconda是關於Python數據分析和科學計算的分發包。
2. Miniconda
使用Anaconda會安裝一百多個依賴包,若是想靈活控制安裝的依賴包或帶寬有限,使用Miniconda是個不錯的選擇。
Conda是個包管理器,Anaconda就是創建在它的基礎上。Conda不僅跨平臺還與語言無關,與pip和virtualenv相結合的做用類似。
Miniconda容許先建立包含Python的安裝包,而後用conda安裝其餘的依賴包。
3. pip
pandas能夠經過pip安裝,但要安裝相關的依賴包。
[plain] view plain copy
pip install pandas
4. 包管理器
能夠用linux的包管理器進行安裝,如
[plain] view plain copy
sudo apt-get install python-pandas
zypper in python-pandas
5. 源碼安裝
從源碼安裝須要安裝最新的Cython,可用easy-install -U cython安裝。源碼位於http://github.com/pydata/pandas,安裝過程爲[plain] view plain copy
git clone git://github.com/pydata/pandas.git
cd pandas
python setup.py install
一 管理虛擬環境軟件
1.1 Mac Python管理虛擬環境軟件安裝-Pyenv具體的流程
1 先安裝管理軟件pyenv
我的安裝信息 87:~ jss$ brew install pyenv Updating Homebrew... ==> Auto-updated Homebrew! Updated 1 tap (homebrew/core). ==> Updated Formulae app-engine-java geth lorem radare2 bit getmail mapnik roswell calabash gtk+ node s-nail cayley gutenberg node@4 sassc conan gxml node@6 saxon diffuse heroku node@8 spigot django-completion igv nspr syncthing docfx jbake odpi tile38 flow jenkins onetime yaml-cpp fluent-bit just openimageio yarn flyway kerl php fn libsass plank ==> Installing dependencies for pyenv: autoconf, pkg-config, openssl, readline ==> Installing pyenv dependency: autoconf ==> Downloading https://homebrew.bintray.com/bottles/autoconf-2.69.high_sierra.b ######################################################################## 100.0% ==> Pouring autoconf-2.69.high_sierra.bottle.4.tar.gz ==> Caveats Emacs Lisp files have been installed to: /usr/local/share/emacs/site-lisp/autoconf ==> Summary 🍺 /usr/local/Cellar/autoconf/2.69: 71 files, 3.0MB ==> Installing pyenv dependency: pkg-config ==> Downloading https://homebrew.bintray.com/bottles/pkg-config-0.29.2.high_sier ######################################################################## 100.0% ==> Pouring pkg-config-0.29.2.high_sierra.bottle.tar.gz 🍺 /usr/local/Cellar/pkg-config/0.29.2: 11 files, 627.2KB ==> Installing pyenv dependency: openssl ==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2n.high_sierra. ######################################################################## 100.0% ==> Pouring openssl-1.0.2n.high_sierra.bottle.tar.gz ==> Caveats A CA file has been bootstrapped using certificates from the SystemRoots keychain. To add additional certificates (e.g. the certificates added in the System keychain), place .pem files in /usr/local/etc/openssl/certs and run /usr/local/opt/openssl/bin/c_rehash This formula is keg-only, which means it was not symlinked into /usr/local, because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries. If you need to have this software first in your PATH run: echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile For compilers to find this software you may need to set: LDFLAGS: -L/usr/local/opt/openssl/lib CPPFLAGS: -I/usr/local/opt/openssl/include For pkg-config to find this software you may need to set: PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig ==> Summary 🍺 /usr/local/Cellar/openssl/1.0.2n: 1,792 files, 12.3MB ==> Installing pyenv dependency: readline ==> Downloading https://homebrew.bintray.com/bottles/readline-7.0.3_1.high_sierr ######################################################################## 100.0% ==> Pouring readline-7.0.3_1.high_sierra.bottle.tar.gz ==> Caveats This formula is keg-only, which means it was not symlinked into /usr/local, because macOS provides the BSD libedit library, which shadows libreadline. In order to prevent conflicts when programs look for libreadline we are defaulting this GNU Readline installation to keg-only.. For compilers to find this software you may need to set: LDFLAGS: -L/usr/local/opt/readline/lib CPPFLAGS: -I/usr/local/opt/readline/include ==> Summary 🍺 /usr/local/Cellar/readline/7.0.3_1: 46 files, 1.5MB ==> Installing pyenv ==> Downloading https://homebrew.bintray.com/bottles/pyenv-1.2.2.high_sierra.bot ######################################################################## 100.0% ==> Pouring pyenv-1.2.2.high_sierra.bottle.tar.gz 🍺 /usr/local/Cellar/pyenv/1.2.2: 593 files, 2.4MB
2 安裝後添加環境變量,在terminal中輸入
sudo vi ~/.bash_profile
3 填寫的具體變量內容
(我的信息:修改後備份 export PATH=${PATH}:/usr/local/mysql/bin )
export PYENV_ROOT=/usr/local/var/pyenv
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
4 使環境變量生效,須要使環境變量生效,運行命令
. ~/.bash_profile
#或者
source ~/.bash_profile
參考:
❌https://www.jianshu.com/p/972512527e9a -簡書/Mac OSX下Python多版本管理器pyenv的安裝及使用
http://blog.csdn.net/suyumingxiangguan/article/details/69942055 -csdn/Mac多Python版本共存,多個獨立Python開發環境切換。
1.2 Mac Python管理虛擬環境軟件安裝-Anaconda具體的流程
a Anaconda簡介
而後就是多方式安裝包或者模塊。其中優先conda,其次pip,再次https://www.lfd.uci.edu/~gohlke/pythonlibs/或者各類官網,最後本身編譯
conda下載的是二進制,pip有的會下載源碼編譯
Anaconda軟件集成了不少python的庫,包括pandas,用python作數據分析的不少人都用這個
Anaconda 是一個用於科學計算的Python發行版,支持 Linux, Mac, Windows系統,提供了包管理與環境管理的功能,能夠很方便地解決多版本python並存、切換以及各類第三方包安裝問題。Anaconda利用工具/命令conda來進行package和environment的管理,而且已經包含了Python和相關的配套工具。 這裏先解釋下conda、anaconda這些概念的差異。是一個打包的集合,裏面預裝好了conda、某個版本的python、衆多packages、科學計算工具等等,因此也稱爲Python的一種發行版。conda能夠理解爲一個工具,也是一個可執行命令,其核心功能是包管理與環境管理。包管理與pip的使用相似,環境管理則容許用戶方便地安裝不一樣版本的python並能夠快速切換。
參考:
http://blog.csdn.net/superdont/article/details/54233017 - csdn/Anaconda的安裝與配置/鏡像的配置
http://www.cnblogs.com/welhzh/p/6009246.html -cnblog/python 安裝anaconda, numpy, pandas, matplotlib 等/terminal conda的操做與鏡像的配置
https://www.zhihu.com/question/47003185 -知乎/如何優雅的安裝Python的pandas?
https://www.jianshu.com/p/2f3be7781451 -簡書/Anaconda使用總結
http://blog.csdn.net/cxsydjn/article/details/71057124 -csdn/Mac OS下 Anaconda Python2 和 Python3 配置/界面簡介和python不一樣版本安裝
https://www.cnblogs.com/amanda-x/p/7739467.html -cnblogs/Anaconda安裝與環境配置
1.3 Mac Python管理虛擬環境軟件安裝-pip具體的流程
1 優缺點
缺點:下載速度慢,20180308安裝中,下載速度介於20-50kb/s
優勢:方便簡單,無需太多的安裝與操做
2 查看已安裝包列表
#適用於mac中python2.x 版本 pip list
#適用於mac中python3.x 版本 pip3 list
3 安裝依賴包和模塊
#適用於mac中python2.x 版本,xx是包名稱 pip install xx
#適用於mac中python3.x 版本,xx是包名稱 pip3 install xx
參考:
✅https://www.cnblogs.com/tensorflownews/p/7298646.html -cnbolg/在 Mac OS X 上安裝 TensorFlow
https://www.jianshu.com/p/4646dedaaff5 -簡書/Python安裝與版本管理/pip使用沙盒使用
二 探索的原由
2.1 具體的問題(報錯)
半路出家,調試代碼中出現如下錯誤
Traceback (most recent call last): File "<stdin>", line 1, in <module>ModuleNotFoundError: No module named 'numpy'
Traceback (most recent call last): File "MLCNN.py", line 8, in <module> import matplotlib.pyplot as pltModuleNotFoundError: No module named 'matplotlib'
Traceback (most recent call last): File "MLCNN.py", line 9, in <module> import scipy.ioModuleNotFoundError: No module named 'scipy'
Traceback (most recent call last): File "MLCNN.py", line 11, in <module> import tensorflow as tfModuleNotFoundError: No module named 'tensorflow'
Traceback (most recent call last):
File "MLCNN.py", line 12, in <module>
import pandas as pd
ModuleNotFoundError: No module named 'pandas'
2.2 先檢查Python的版本與路徑
1 查看python版本
#注意:‘-V‘中‘V’爲大寫字母,只有一個‘-’ python -V
#注意:‘--version'中有兩個‘-’ python --version
2 查看python安裝位置
python3以上的版本 注意print的時候使用的是括號,python3如下版本的不須要括號
python -c "import sys; print (sys.executable)"
python -c "import os; print (os.sys.executable)" python -c "import os; path = os.sys.executable;folder=path[0 : path.rfind(os.sep)]; print folder"
2.3 安裝包——Numpy(pip)
1 查看Numpy版本
python -c "import numpy; print (numpy.version.version)"
python3 -c "import numpy; print (numpy.__version__)"
2 查看Numpy安裝路徑
#python2.x版本 python -c "import numpy; print (numpy.__file__)"
python -c "import numpy; print (numpy.__file__)"
#python3.x版本 python3 -c "import numpy; print (numpy.__file__)"
python3 -c "import numpy; print (numpy.__file__)"
3 安裝
$pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose --prefix=~/local
4 將package安裝到指定目錄:經過源碼安裝一個python包的時候,例如安裝xlrd,目標路徑爲/usr/local/lib/python2.7/site-packages/
$ pip install -t /usr/local/lib/python2.7/site-packages/ xlrd
5 或者我已經測試成功的,網站爲
$mac os x: Python 3 安裝(scipy,numpy,matplotlib. . .)
2.4 安裝包——matplotlib
方法一 使用Pip
先安裝pip,參考標準pip安裝指令
curl -O https://bootstrap.pypa.io/get-pip.py
安裝到Python2.7
python get-pip.py
安裝到Python3
python3 get-pip.py
安裝Matplotlib
pip install matplotlib
報錯:猜想多是由於多個版本形成的問題,個人目標安裝是python36,最後在這個論壇裏找到解決方法。
Requirement already satisfied: matplotlib in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/pythonRequirement already satisfied: numpy>=1.5 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib)Requirement already satisfied: python-dateutil in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib)Requirement already satisfied: tornado in ./Library/Python/2.7/lib/python/site-packages (from matplotlib)Requirement already satisfied: pyparsing>=1.5.6 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib)Requirement already satisfied: nose in ./Library/Python/2.7/lib/python/site-packages (from matplotlib)Requirement already satisfied: singledispatch in ./Library/Python/2.7/lib/python/site-packages (from tornado->matplotlib)Requirement already satisfied: certifi in ./Library/Python/2.7/lib/python/site-packages (from tornado->matplotlib)Requirement already satisfied: backports_abc>=0.4 in ./Library/Python/2.7/lib/python/site-packages (from tornado->matplotlib)Requirement already satisfied: six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from singledispatch->tornado->matplotlib)
個人pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.altgraph (0.10.2)appnope (0.1.0)backports-abc (0.5)backports.functools-lru-cache (1.5)backports.shutil-get-terminal-size (1.0.0)bdist-mpkg (0.5.0)bleach (2.1.2)bonjour-py (0.3)certifi (2018.1.18)configparser (3.5.0)cycler (0.10.0)decorator (4.2.1)entrypoints (0.2.3)enum34 (1.1.6)functools32 (3.2.3.post2)html5lib (1.0.1)ipykernel (4.8.2)ipython (5.5.0)ipython-genutils (0.2.0)ipywidgets (7.1.2)Jinja2 (2.10)jsonschema (2.6.0)jupyter (1.0.0)jupyter-client (5.2.2)jupyter-console (5.2.0)jupyter-core (4.4.0)lxml (4.1.1)macholib (1.5.1)Markdown (2.6.9)MarkupSafe (1.0)matplotlib (2.1.2)mistune (0.8.3)modulegraph (0.10.4)mpmath (1.0.0)nbconvert (5.3.1)nbformat (4.4.0)nose (1.3.7)notebook (5.4.0)numpy (1.14.1)pandas (0.22.0)pandocfilters (1.4.2)pathlib2 (2.3.0)pexpect (4.4.0)pickleshare (0.7.4)pip (9.0.1)prompt-toolkit (1.0.15)ptyprocess (0.5.2)py2app (0.7.3)Pygments (2.2.0)pyobjc-core (2.5.1)pyobjc-framework-Accounts (2.5.1)pyobjc-framework-AddressBook (2.5.1)pyobjc-framework-AppleScriptKit (2.5.1)pyobjc-framework-AppleScriptObjC (2.5.1)pyobjc-framework-Automator (2.5.1)pyobjc-framework-CFNetwork (2.5.1)pyobjc-framework-Cocoa (2.5.1)pyobjc-framework-Collaboration (2.5.1)pyobjc-framework-CoreData (2.5.1)pyobjc-framework-CoreLocation (2.5.1)pyobjc-framework-CoreText (2.5.1)pyobjc-framework-DictionaryServices (2.5.1)pyobjc-framework-EventKit (2.5.1)pyobjc-framework-ExceptionHandling (2.5.1)pyobjc-framework-FSEvents (2.5.1)pyobjc-framework-InputMethodKit (2.5.1)pyobjc-framework-InstallerPlugins (2.5.1)pyobjc-framework-InstantMessage (2.5.1)pyobjc-framework-LatentSemanticMapping (2.5.1)pyobjc-framework-LaunchServices (2.5.1)pyobjc-framework-Message (2.5.1)pyobjc-framework-OpenDirectory (2.5.1)pyobjc-framework-PreferencePanes (2.5.1)pyobjc-framework-PubSub (2.5.1)pyobjc-framework-QTKit (2.5.1)pyobjc-framework-Quartz (2.5.1)pyobjc-framework-ScreenSaver (2.5.1)pyobjc-framework-ScriptingBridge (2.5.1)pyobjc-framework-SearchKit (2.5.1)pyobjc-framework-ServiceManagement (2.5.1)pyobjc-framework-Social (2.5.1)pyobjc-framework-SyncServices (2.5.1)pyobjc-framework-SystemConfiguration (2.5.1)pyobjc-framework-WebKit (2.5.1)pyOpenSSL (0.13.1)pyparsing (2.2.0)python-dateutil (2.6.1)pytz (2018.3)pyzmq (17.0.0)qtconsole (4.3.1)scandir (1.7)scipy (0.13.0b1)Send2Trash (1.5.0)setuptools (18.5)simplegeneric (0.8.1)singledispatch (3.4.0.3)six (1.11.0)subprocess32 (3.2.7)sympy (1.1.1)terminado (0.8.1)testpath (0.3.1)tornado (4.5.3)traitlets (4.3.2)virtualenv (15.1.0)wcwidth (0.1.7)webencodings (0.5.1)widgetsnbextension (3.1.4)xattr (0.6.4)zope.interface (4.1.1)
執行的命令
python3 -m pip install --user --upgrade matplotlib
方法二 Macports
Python 2.7
sudo port install py27-pipsudo pip-2.7 install matplotlib
Python 3.6:
sudo port install py36-pipsudo pip-3.6 install matplotlib
2.5 安裝包——scipy(pip)
python3 -m pip install scipy import scipy
測試一下
import scipy
2.6 安裝pandas
1. Anaconda:安裝pandas、Python和SciPy最簡單的方式是用Anaconda。Anaconda是關於Python數據分析和科學計算的分發包。
2. Miniconda
使用Anaconda會安裝一百多個依賴包,若是想靈活控制安裝的依賴包或帶寬有限,使用Miniconda是個不錯的選擇。
Conda是個包管理器,Anaconda就是創建在它的基礎上。Conda不僅跨平臺還與語言無關,與pip和virtualenv相結合的做用類似。
Miniconda容許先建立包含Python的安裝包,而後用conda安裝其餘的依賴包。
3. Pypi
pandas能夠經過pip安裝,但要安裝相關的依賴包。
[plain] view plain copy
pip install pandas
4. 包管理器
能夠用linux的包管理器進行安裝,如
[plain] view plain copy
sudo apt-get install python-pandas
zypper in python-pandas
5. 源碼安裝
從源碼安裝須要安裝最新的Cython,可用easy-install -U cython安裝。源碼位於http://github.com/pydata/pandas,安裝過程爲
[plain] view plain copy
git clone git://github.com/pydata/pandas.git
cd pandas
python setup.py install
2.7 安裝TensorFlow(pip)
#python2版本 pip install tensorflow
#python3版本 pip3 install tensorflow
安裝成功後,若是仍然報錯
Traceback (most recent call last):
File "MLCNN.py", line 10, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
解決方案1——卸載重裝tensorflow(未解決)
(pip重裝後測試無效果)
$ pip uninstall tensorflow
$ pip3 uninstall tensorflow
http://bbs.csdn.net/topics/392322815?list=lz -csdn/Python與TensorFlow安裝遇到問題求助
http://blog.csdn.net/evaljy/article/details/70209957 -csdn/tensorflow在win上的安裝常見錯誤及正確安裝步驟(包含anaconda spyder)/報錯集合
解決方案2——用Anaconda來進行激活使用(未解決)
首先安裝Anaconda,安裝成功後,建立一個conda環境
conda create -n tensorflow pip python = 2.7
conda create -n tensorflow pip python = 3.6 #或python = 3.3等
激活環境
source activate tensorflow
# (targetDirectory)$ Your prompt should change
在環境中安裝Tensorflow
pip install --ignore-installed --upgrade \ https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.6.0-py2-none-any.whl #TensorFlow for Python 2.7的純CPU版本
pip install --ignore-installed --upgrade \ https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.6.0-py3-none-any.whl #Python 3.4,3.5或3.6
參考:
https://www.tensorflow.org/install/install_mac -tensorflow官網
正確的安裝方法
⭐️http://blog.csdn.net/u012373815/article/details/73555460 -csdn/mac/linux 安裝tensorflow和安裝Anaconda
tensorflow拓展學習
http://www.tensorflownews.com/category/course/ -tensorflownews/tensorflownews/我的網站
參考:
✅http://www.cnblogs.com/tensorflownews/p/7298646.html -cnblogs/在 Mac OS X 上安裝 TensorFlow
參考:
https://jingyan.baidu.com/article/fec7a1e5ec30341190b4e7e5.html -Mac下如何安裝配置Homebrew
http://blog.csdn.net/ybuiipl/article/details/60875304 -Linux/numpy的下載與安裝教程——(解決No module named numpy問題)
https://www.cnblogs.com/klchang/p/4543032.html -python和numpy的版本、安裝位置
https://www.zhihu.com/question/21731171 -安裝Numpy
http://blog.csdn.net/ciyiquan5963/article/details/77531932 -Mac/MAC 使用pycharm出現ImportError: No module named numpy 解決方法
http://rstevens.iteye.com/blog/1214143 -安裝python package到指定目錄
http://blog.csdn.net/techfield/article/details/52618130 -多版本Python共存時pip給指定版本的python安裝package的方法
https://www.jianshu.com/p/21bb9d06cf79 -[Mac] Python Numpy Scipy Matplotlib 快速安裝
⭐️http://blog.topspeedsnail.com/archives/704 -mac os x: Python 3 安裝(scipy,numpy,matplotlib. . .)
https://stackoverflow.com/questions/33888760/importerror-no-module-named-matplotlib -ImportError: No module named matplotlib
http://blog.csdn.net/a595130080/article/details/55506237 - tensorflow
2018-03-0809:00:00
2018-03-0821:17:12