ubuntu 安裝python,easy_install和pip


ubuntu12.04默認安裝的python為

ms@ubuntums:~$ python
Python 2.7.3 (default, Aug 1 2012, 05:16:07)

我需要用python2.7.5,又找不到適合的升級的方法,只好安裝python2.7.5

首先下載python源碼:

1、下載Python 2.7.5源碼:

wget http://www.python.org/ftp/python/2.7.2/Python-2.7.5.tgz

下載

2、解壓源碼包:

tar -zxvf Python-2.7.2.tgz

3、編譯:

cd Python-2.7.2

./configure  --prefix=/usr

4、make&&make install

安裝完成后測試web界面可以正常打開了,但是使用yum安裝軟件的時候會發現不能使用,原因是yum與python有依賴關系,yum是急於python寫的,運行yum命令時會調用pyton;

vi /usr/bin/yum

將#!/usr/bin/pyton 改成:#!/usr/bin/pyton2.6,改成你系統默認的版本即可,不然他會調用高版本的python軟件包,但是是找不到的,需要做相關配置才行,這里為了方便就直接改了就可以使用了。

 我安裝的結果報錯:

/usr/bin/install -c python /usr/bin/python2.7
/usr/bin/install: 無法刪除"/usr/bin/python2.7": 權限不夠
make: *** [altbininstall] 錯誤 1

ubuntu安裝新python不要卸載舊版本的python,因為系統很多軟件都依賴它。

我想原因應該是python2.7.3和Python2.7.5都已2.7開頭,不能共存。

Ubuntu中安裝多個版本Python

Ubuntu中默認就自帶了python的2.5版本,結果我還是裝了一個python的2.6版本,在網上查了下才知道python的2.5版本是目前使用者最多的版本,一些python的庫都是用的這個版本,無奈只好再換回python的2.5版本了,其實在linux系統中多個python版本是可以共存的,只不過在終端中運行的時候,輸入 python2.5 或者 python2.6就能進入不同的版本了,而且在你的*.py文件中可以用 #!/usr/bin/python  來指定程序的解釋器版本,不過這樣使用起來有些不方便,所以就把/usr/bin/python這個快捷方式的指向修改下好了。

: ~$ sudo rm /usr/bin/python

:~$ sudo ln -s /usr/include/python2.5 /usr/bin/python

這樣在終端中輸入python默認就是 2.5版本了。

很簡單的,呵呵,我也是初學,這個沒什么難度,就當個學習筆記吧

 

安裝easy_install:

Unix-based Systems including Mac OS X

Download ez_setup.py and run it using the target Python version. The script will download the appropriate version and install it for you:

> wget https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py -O - | python

Note that you will may need to invoke the command with superuser privileges to install to the system Python.

Alternatively, on Python 2.6 and later, Setuptools may be installed to a user-local path:

> wget https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py
> python ez_setup.py --user

 或者:

udo apt-get install python-setuptools 來安裝

安裝完后運行easy_install:

ms@ubuntums:~$ easy_install
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

[Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/test-easy-install-9879.pth'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

/usr/local/lib/python2.7/dist-packages/

Perhaps your account does not have write access to this directory? If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account. If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.

For information on other options, you may wish to consult the
documentation at:

http://packages.python.org/distribute/easy_install.html

 

這個錯誤不知怎么回事,好像是沒有權限,我切換到root用戶:

root@ubuntums:/home/ms# easy_install pip

 ok。

 

安裝Pip

從pip v1.5.1開始,安裝變得很簡單,直接以管理員身份,在get-pip.py所在的目錄下運行

[python]  view plain  copy
 
  1. python get-pip.py  

執行完成后,在python的安裝目錄下的Scripts子目錄下,可以看到pip.exe、pip2.7.exe、pip2.exe等,這就表示pip安裝成功了。

注意:要想能在命令行上直接運行pip程序,需要scripts這個目錄加入到環境變量PATH中。

pip安裝的時候還可以使用安裝選項進行安裝,比如指定get-pip.py所在的位置:

 

  1. python get-pip.py --no-index --find-links=c:\downloads  

 

【Usage】

Install a package from PyPI:

[python]  view plain  copy
 
  1. pip install SomePackage  

安裝特定版本的package,通過使用==, >=, <=, >, <來指定一個版本號。
pip install 'Markdown<2.0'
pip install 'Markdown>2.0,<2.0.3

 

 

 
 


免責聲明!

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



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