Python

升級到 Python 3.3 和設置 Django 的問題

  • December 8, 2012

我是 Linux 新手,正在嘗試在我的機器上設置 Python / Django!我從源文件安裝了 Python 3.3,並將其編譯為/usr/local/bin. /usr/bin/python然後我在and之間創建了一個符號連結/usr/local/bin/python3,這樣每當我從命令行呼叫 python 時,它都會使用最新版本。

現在我正在嘗試安裝 MySQL Python,我得到以下輸出:

apt-get install python-mysqldb

Reading package lists... Done
Building dependency tree
Reading state information... Done
python-mysqldb is already the newest version.
The following extra packages will be installed:
 apt-listchanges python-apt
Suggested packages:
 python-glade2 python-gtk2 python-apt-dbg python-vte python-apt-doc
The following packages will be upgraded:
 apt-listchanges python-apt
2 upgraded, 0 newly installed, 0 to remove and 142 not upgraded.
3 not fully installed or removed.
Need to get 0 B/394 kB of archives.
After this operation, 250 kB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Traceback (most recent call last):
 File "/usr/bin/apt-listchanges", line 28, in <module>
   import apt_pkg
ImportError: No module named 'apt_pkg'

有想法該怎麼解決這個嗎?或者關於如何清理這個安裝的任何提示(如果這個太壞了)?

Debian 中太多的軟體包仍然依賴 Python 2.x。結果,幾乎每個人都需要安裝 Python 2.x。

通常,要同時擁有 Python 2.x 和 3.x,需要執行以下操作:

  • /usr/bin/python指的是 Python 2.x 二進製文件
  • /usr/bin/python3指的是 Python 3.x 二進製文件

要查看您機器上目前安裝的 Python 版本是什麼,請執行:

ls -l /usr/bin/python*

(結果例如/usr/bin/python2.7

要刪除符號連結:rm -i /usr/bin/python

要創建符號連結:ln -s /usr/bin/python2.7 /usr/bin/python

引用自:https://serverfault.com/questions/456172