【轉】linux和windows下安裝python集成開發環境及其python包


本系列分為兩篇:

1、【轉】windows和linux中搭建python集成開發環境IDE

2、【轉】linux和windows下安裝python集成開發環境及其python包

3、windows和linux中搭建python集成開發環境IDE——如何設置多個python環境

 

參考:http://blog.csdn.net/pipisorry/article/details/39902327

一、安裝Python集成開發環境IDE

參考linux和windows中搭建python開發環境

 

 二、python包的安裝

FOR LINUX:

  和Python(x,y)不一樣,在Ubuntu中需要手工安裝科學計算的各個模塊,下面介紹如何在linux下安裝NumPy, SciPy, matplotlib, scikit-learn,NLTK,gensim,PIL,OpenCV,PyQt4, Spyder, Cython, SWIG, ETS
在Ubuntu下安裝Python模塊通常有3種方法:1)使用apt-get;2)使用pip命令(推薦);3)easy_instal

 

  apt-get命令是Ubuntu自帶的包管理命令,而pip和easy_instal則是專門為Python安裝擴展模塊的linux工具,通常pip會下載擴展模塊的源代碼並編譯安裝

 

  Ubuntu 12.04中缺省安裝了Python2.7.3,首先通過下面的命令安裝pip,pip是Python的一個安裝和管理擴展庫的工具。[Python的包管理工具]

 

  sudo apt-get install python-pip

 

  Ubuntu 14.04中缺省安裝了Python3,自帶pip,不用安裝。

  (實踐證明,作者這個有誤,其實並沒有預裝,也需要自己安裝!但是有自帶easy_install工具)  

 

  

 可能使用apt-get方法安裝pip會出現如下問題, 

$ sudo apt-get install python-pip
$ pip
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    load_entry_point('pip==1.5.4', 'console_scripts', 'pip')()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 351, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2363, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2088, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 11, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar # noqa
  File "/usr/lib/python2.7/dist-packages/pip/vcs/mercurial.py", line 9, in <module>
    from pip.download import path_to_url
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 25, in <module>
    from requests.compat import IncompleteRead
ImportError: cannot import name IncompleteRead

解決1如下:

參考:【pip stops with ImportError for request-Modul

 應該是apt-get上面的庫比較老,所以出現問題,可以使用easy_install升級pip版本即可解決:

$ sudo easy_install -U pip
Searching for pip
Reading https://pypi.python.org/simple/pip/
Best match: pip 1.5.6
Downloading https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz#md5=01026f87978932060cc86c1dc527903e
Processing pip-1.5.6.tar.gz
Writing /tmp/easy_install-u_hfjN/pip-1.5.6/setup.cfg
Running pip-1.5.6/setup.py -q bdist_egg --dist-dir /tmp/easy_install-u_hfjN/pip-1.5.6/egg-dist-tmp-oG6xQ8
warning: no files found matching 'pip/cacert.pem'
warning: no files found matching '*.html' under directory 'docs'
warning: no previously-included files matching '*.rst' found under directory 'docs/_build'
no previously-included directories found matching 'docs/_build/_sources'
Adding pip 1.5.6 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/bin

Installed /usr/local/lib/python2.7/dist-packages/pip-1.5.6-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip

 

解決2如下:使用以下方法安裝最新pip

參考:【Install Python packages on Ubuntu 14.04

Of course, the starting point is to get pip installed. Official instructions are also available for installing pippip depends on setuptools, but we can install both using the get-pip.py script, as described at the install link. To be concrete, I did the following:

$ cd ~/Downloads $ curl -O https://bootstrap.pypa.io/get-pip.py $ python get-pip.py --user 

If you don’t have curl installed, this can be remedied using:

$ sudo apt-get install curl

Because we have chosen local installation, the path ~/.local/bin has to be added to our path. To do that, add the following to the end of your ~/.bashrc file:

# include .local/bin for local python scripts
export PATH=~/.local/bin:$PATH

Then, source ~/.bashrc:

$ source ~/.bashrc 

Try the following to see if you get similar results and to make sure the basic setup is working:

$ which pip
/home/cstrelioff/.local/bin/pip
$ pip --version pip 1.5.6 from /home/cstrelioff/.local/lib/python2.7/site-packages (python 2.7) 

Of course, your username should be in the path, but the output should look something like the above.

比較:

 

  區別

 

  pip 官網的說法,pip 改善了不少 easy_install 的缺點,如此說來 pip 應該是略勝一籌,不過它還不能夠完全取代對方,因為目前有很多套件還是得用 easy_install 安裝

 

  詳細

 

  安裝套件:

 

easy_install PackageName

 

更新套件:

 

easy_install -U PackageName

 

移除套件:

 

easy_install -m PackageName

 

顯示說明:

 

easy_install --showhelp

 

pip (pip installs packages) 的安裝與使用

 

pip 的安裝方法:

 

easy_install pip

 

有趣的是,pip 可以透過 easy_install 安裝,而且也會裝到 Scripts 資料夾下。

 

安裝套件:

 

pip install PackageName

 

更新套件:

 

pip install -U PackageName

 

移除套件:

 

pip uninstall PackageName

 

搜尋套件:

 

pip search PackageName

 

顯示說明:

 

pip help

 

查看安裝了那些python包

  pip list

 

 

 

apt-get 與 pip 的區別?可參考:apt get install vs pip install

 

PyPI is the Python Package index — repository of python modules.

pip is used to download and install packages directly from PyPI. PyPI is hosted by Python Software Foundation. It is a specialized package manager that only deals with python packages.

apt-get is used to download and install packages from Ubuntu repositories which are hosted by Canonical.

Some of the differences between installing python packages from apt-get and pip are as follows:

  • Canonical only provides packages for selected python modules. Whereas, PyPI hosts a much broader range of python modules. So, there are a lot of python modules which you won't be able to install using apt-get.

  • Canonical only hosts a single version of any package (generally the latest or the one released in recent past). So, with apt-get we cannot decide the version of python-package that we want. pip helps us in this situation. We can install any version of the package that has previously been uploaded on PyPI. This is extremely helpful in case of conflict in dependencies.

  • apt-get installs python modules in system-wide location. We cannot just install modules in our project virtualenvpip solves this problem for us. If we are using pip after activating the virtualenv, it is intelligent enough to only install the modules in our project virtualenv. As mentioned in previous point, if there is a version of a particular python package already installed in system-wide location, and one of our project requires an older version of the same python package, in such situations we can use virtualenv and pip to install that older version of python package without any conflicts.

  • As @Radu Rădeanu pointed out in this answer, there would generally be difference in names of packages as well. Canonical usually names Python 2 packages as python-<package_name> and Python 3 packages as python3-<package_name>. Whereas for pip we generally just need to use <package_name> for both Python 2 as well as Python3 packages.

Which one should you use:

  Both apt-get and pip are mature package managers which automatically install any other package dependency while installing. You may use anyone as you like. However, if you need to install a particular version of python-package, or install the package in a virtualenv, or install a package which is only hosted on PyPI; only pip would help you solve that issue. Otherwise, if you don't mind installing the packages in system-wide location it doesn't really matter whether you use apt-get or pip.

 

Your main problem is to find the right package name in both cases:

pip search pyudev

will give you the right name for the package you want to install using pip install, as

apt-cache search pyudev

will give you the right name for the package you want to install using apt-get install:可以使用這兩條命令搜索相應的包

radu@Radu: ~ $ pip search pyudev pyudev - A libudev binding radu@Radu: ~ $ apt-cache search pyudev python-pyudev - Python bindings for libudev python3-pyudev - Python3 bindings for libudev

So, in conlusion, the correspondent of sudo apt-get install python-pyudev is sudo pip install pyudev, not sudo pip install python-pyudev.

Now depends on you what you want to choose when you want to install a python package: pip or apt-get. See for example this Q&A about difference in installing a package using pip and apt-get.

 

Test installation測試python拓展安裝包是否安裝成功

運行 python

然后import ×××,沒有提示錯誤就說明安裝成功

 

 

下面在linux下安裝NumPy,SciPy和matplotlib

1. 通過apt-get命令快速安裝
sudo apt-get install python-numpy
sudo apt-get install python-scipy
sudo apt-get install python-matplotlib

 可以在pycharm console中查看 numpy 版本和路徑:
import numpy
print numpy.__version__
print numpy.__file__


2. 通過pip編譯安裝

可以先用apt-get命令安裝所有編譯所需的庫:
sudo apt-get build-dep python-numpy
sudo apt-get build-dep python-scipy
然后通過pip命令安裝:
sudo pip install numpy
sudo pip install scipy
通過build-dep會安裝很多庫,包括Python 3.2。


PyQt4和Spyder
下面的命令安裝PyQt4,Qt界面設計器,PyQt4的開發工具以及文檔:
sudo apt-get install python-qt4
sudo apt-get install qt4-designer
sudo apt-get install pyqt4-dev-tools
sudo apt-get install python-qt4-doc
安裝完畢之后,文檔位於:
/usr/share/doc/python-qt4-doc
安裝好PyQt4之后通過下面的命令安裝Spyder:
sudo apt-get install spyder

由於Spyder經常更新,通過下面的命令可以安裝最新版
sudo pip install spyder --upgrade


cython和SWIG
Cython和SWIG是編寫Python擴展模塊的工具:
sudo pip install cython
sudo apt-get install swig
輸入 cython --version 和 swig -version 查看版本。


ETS
ETS是enthought公司開發的一套科學計算軟件包,其中的Mayavi通過VTK實現數據的三維可視化。
首先通過下面的命令安裝編譯ETS所需的庫:
sudo apt-get install python-dev libxtst-dev scons python-vtk  pyqt4-dev-tools python2.7-wxgtk2.8 python-configobj
sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev

創建ets目錄,並在此目錄下下載ets.py,運行ets.py可以復制最新版的ETS源程序,並安裝:
mkdir ets
cd ets
wget https://github.com/enthought/ets/raw/master/ets.py
python ets.py clone
sudo python ets.py develop
#sudo python ets.py install    或者運行install安裝

如果一切正常,那么輸入 mayavi2 命令則會啟動mayavi。

 

linux下安裝scikit-learn

Building scikit-learn with pip

 

This is usually the fastest way to install or upgrade to the latest stablerelease:

pip install --user --install-option="--prefix=" -U scikit-learn

Note:

1. The --user flag ask pip to install scikit-learn in the$HOME/.localfolder therefore not requiring root permission. This flag should make pipignore any old version of scikit-learn previously installed on the system whilebenefitting from system packages for numpy and scipy. Those dependencies canbe long and complex to build correctly from source.

2. The --install-option="--prefix=" flag is only required if Python has adistutils.cfg configuration with a predefinedprefix= entry.

From source package

Download the source package from http://pypi.python.org/pypi/scikit-learn/, unpack the sources and cd into the source directory.

This packages uses distutils, which is the default way of installingpython modules. The install command is:

python setup.py install

[Installing scikit-learn]

 

 

linux下安裝NLTK

  1. Install Setuptools: http://pypi.python.org/pypi/setuptools
  2. Install Pip: run sudoeasy_installpip
  3. Install Numpy (optional): run sudo pip install-Unumpy
  4. Install NLTK: run sudopipinstall-Unltk
  5. Test installation: run python then type importnltk

Note:Mac/Unix都通過這種方式安裝nltk

[http://www.nltk.org/install.html]

 

 

linux下安裝gensim

1. #pip install gensim

2. 下載gensim-0.10.3.tar_2.gz

unzipped the source tar.gz package, you'll need to run:
#python setup.py test
#python setup.py install

Note:gensim依賴NumPy和SciPy,要先安裝

gensim/install

 

linux下安裝OpenCV

python-opencv:

環境
ubuntu 12.04 LTS
python 2.7.3
opencv 2.3.1-7

安裝依賴
sudo apt-get install libopencv-*
sudo apt-get install python-opencv
sudo apt-get install python-numpy

在python中使用OpenCV

python使用opencv進行人臉識別

Ubuntu 12.04下安裝OpenCV 2.4.2

UBUNTU下安裝OPENCV和測試python-opencv

Ubuntu下Opencv與Python的協作

ubuntu 下 安裝 python-opencv 配置

dpkg -L python-opencv命令查看,搜索安裝到何處

root@ubuntu:~#dpkg -L python-opencv
/.
/usr
/usr/share
/usr/share/python-support
/usr/share/python-support/python-opencv.public
/usr/share/doc
/usr/share/doc/python-opencv
/usr/share/doc/python-opencv/copyright
/usr/share/pyshared
/usr/share/pyshared/cv.py
/usr/lib
/usr/lib/pyshared
/usr/lib/pyshared/python2.7
/usr/lib/pyshared/python2.7/cv2.so
/usr/share/doc/python-opencv/changelog.Debian.gz

測試opencv安裝好沒:

[python]  view plain copy 在CODE上查看代碼片 派生到我的代碼片
 
  1. ###################################  
  2. #   coding=utf-8  
  3. #   !/usr/bin/env python  
  4. #   __author__ = 'pipi'  
  5. #   ctime 2014.10.12  
  6. #   測試opencv  
  7. ###################################  
  8. import cv  
  9. if __name__ == '__main__':  
  10.     img = cv.LoadImageM ("faces.jpg")   # 打開圖像  
  11.     cv.NamedWindow ("ShowImage")        # 創建窗口  
  12.     cv.ShowImage ("ShowImage", img)     # 顯示圖像  
  13.     cv.WaitKey (0)  

python-opencv這個基本過時了,cv2是opencv自己帶的python綁定,編譯opencv應該就有了

python-opencv:

更新下載更新軟件包列表信息
apt-get update

查詢OpenCV相關軟件包
$ apt-cache search opencv

libcv-dev - development files for libcv
libcv1 - computer vision library
libcvaux-dev - development files for libcvaux
libcvaux1 - computer vision extension library
libhighgui-dev - development files for libhighgui
libhighgui1 - computer vision GUI library
opencv-doc - OpenCV documentation and examples
python-opencv - Python bindings for the computer vision library

//以上內容可能是沒有及時更新
//用命令行$ apt-cache search opencv在ubuntu(12.04LTS)找到的最新的opencv版本是2.1
harpia - Image Processing/Computer Vision Automatic Prgm. Tool
libcv-dev - development files for libcv
libcv2.1 - computer vision library
libcvaux-dev - development files for libcvaux
libcvaux2.1 - computer vision extension library
libhighgui-dev - development files for libhighgui
libhighgui2.1 - computer vision GUI library
opencv-doc - OpenCV documentation and examples
python-opencv - Python bindings for the computer vision library

在這里,OpenCV的庫CxCore和Cv都被包含入Deb包libcv中。
安裝相關軟件包
如果只是用來運行OpenCV程序,僅需安裝libcv1,libcvaux1,libhighgui1:
apt-get install libcv1 libcvaux1 libhighgui1
如果你要使用OpenCV來編寫程序,那么還需要安裝libcv-dev,libcvaux-dev,libhighgui-dev包。
apt-get install libcv-dev libcvaux-dev libhighgui-dev

文檔在opencv-doc包中,python-opencv是OpenCV的Python語言包,可根據需要安裝。

測試安裝包
測試是否安裝成功,你可以使用以下的命令行編譯位於源代碼包中的drawing.c例子:
g++ drawing.c `pkg-config opencv --libs --cflags opencv` -o drawing
成功編譯后你應該能夠可以執行./drawing看到highgui輸出窗口的結果了.

Debian/Ubuntu下安裝

c-opencv?

為了編譯OpenCV需要下載cmake編譯工具,和一些依賴庫:
sudo python setup.py install
sudo apt-get install build-essential
sudo apt-get install cmake
sudo apt-get install cmake-gui
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libjpeg-dev libpng-dev libtiff-dev libjasper-dev
然后終端輸入http://sourceforge.net/projects/opencvlibrary/files/latest/download?source=files下載opencv源代碼

或者從 http://sourceforge.net/projects/opencvlibrary/下載最新版的OpenCV源代碼,並解壓。

然后創建編譯用的目錄release,並啟動cmake-gui:
mkdir release
cmake-gui


在界面中選擇OpenCV源代碼的目錄,和編譯輸出目錄release,然后按Configure按鈕,並根據需要設置各個編譯選項,最后點Generate按鈕,退出cmake-gui界面。進入編譯路徑,執行下面的命令:
cd release
make
sudo make install
安裝完畢之后,啟動IPython,並輸入 import cv2 測試OpenCV是否能正常載入。在Ubuntu下貌似OpenCv不兼容使用apt-get安裝numpy和scipy貌似,好像版本過低。我的解決方法是下了最新的numpy和scipy,然后自己編譯安裝上去的。為了安裝這兩個軟件,我又安裝了另外一大堆東西。

ps:在Ubuntu下貌似OpenCv不兼容使用apt-get安裝numpy和scipy貌似,版本過低。解決方法是下載最新的numpy和scipy,然后自己編譯安裝上去的。為了安裝這兩個軟件,還要安裝了另外一大堆東西。

[http://blog.csdn.net/pipisorry/article/details/39902327]

 

 

for windows

windows下安裝NumPy,SciPy,matplotlib,pil, gensim, django,pandas等python拓展包,直接下載exe文件或者whl文件安裝(前提已安裝python)

windows安裝包下載[Unofficial Windows Binaries for Python Extension Packages]

whl文件的安裝

1. 安裝whl拓展名的包需要pip,安裝pip【安裝pip】(python3自帶,不用安裝)

2. 安裝whl文件

1>打開python,在python命令行中輸入(如果提示install錯誤,見2>)

pip install Pillow-2.7.0-cp34-none-win_amd64.whl

2>直接在cmd中輸入上面的安裝命令

 

windows下安裝PIL

1 win32下安裝pil.whl文件

下載http://www.pythonware.com/products/pil/

2 win64下安裝pil:

沒有pil安裝包,可用pillow(里面包含pil)替代

pip install pillow

 

windows下安裝gensim

Note:gensim依賴NumPy和SciPy

1 pip安裝:

pip install gensim    #python3自帶pip

2  下載原碼安裝:

https://pypi.python.org/pypi/gensim#downloads 

unpack the source  gensim-0.10.3.tar.gz and run

`D:\Downloads\Programming\Python\gensim-0.10.3> python setup.py install`

[scripygensimwindows64 位 安裝python 擴展包pythoncollection]

Documentation

Manual for the gensim package is available in HTML. Itcontains a walk-through of all its features and a complete reference section.It is also included in the source distribution package.

[https://pypi.python.org/pypi/gensim#downloads]

pip安裝gensim時出現錯誤:

#【徹底解決 error: Unable to find vcvarsall.bat

1 pip install for python 2.7:

C:\Users\pi\pip\pip.log:

Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat). Get it fromhttp://aka.ms/vcpython27

an integer is required

解釋:For Windows installations:

While running setup.py for package installations, Python 2.7 searches for an installed Visual Studio 2008. You can trick Python to use a newer Visual Studio by setting the correct path inVS90COMNTOOLS environment variable before callingsetup.py.

Execute the following command based on the version of Visual Studio installed:

    Visual Studio 2010 (VS10): SET VS90COMNTOOLS=%VS100COMNTOOLS%
    Visual Studio 2012 (VS11): SET VS90COMNTOOLS=%VS110COMNTOOLS%
    Visual Studio 2013 (VS12): SET VS90COMNTOOLS=%VS120COMNTOOLS%

【http://stackoverflow.com/questions/2817869/error-unable-to-find-vcvarsall-bat?rq=1

Installing gensim in windows 7

2 pip install for python3.4:

    TypeError: 'str' object cannot be interpreted as an integer
    Unable to find vcvarsall.bat

    'str' object cannot be interpreted as an integer

解決:只安裝visual studio 2010中c++就ok了

Important Note:【http://stackoverflow.com/questions/2817869/error-unable-to-find-vcvarsall-bat?rq=1

If you are using a Python version more recent than Python 2.7 (especially any Python 3.x), you most likely need a version of Visual Studio C++other than the 2008 version.

See bottom for details.

Installing Windows SDK 7.1 and then re-installing MS 2010 C++ Express Edition fixed the problem.

【https://groups.google.com/forum/#!msg/gensim/8Qe-nlBMncU/4Kl0zh4ZtuoJ

python在windows下通過pip安裝帶有c擴展的包時,如果是python 2.7,需要vs2008,如果是python 3.x,需要vs2010,版本錯了都不行,更別提mingw。因為c運行時不兼容的原因。

http://www.zhihu.com/question/26857761

3Difficulty installing Gensim using from source and pip
[http://blog.csdn.net/pipisorry/article/details/39902327]

 

 

windows下pythonQt的安裝和使用


 

Test installation測試python拓展安裝包是否安裝成功

運行 python

然后import ×××,沒有提示錯誤就說明安裝成功

from:http://blog.csdn.net/pipisorry/article/details/39902327

ref:Ubuntu中安裝Python科學計算環境

Ubuntu-Python2.7安裝 scipy,numpy,matplotlib

Mountail Lion 上的 Python 科研環境的搭建

 

版權聲明:本文為博主http://blog.csdn.net/pipisorry原創文章,未經博主允許不得轉載。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM