1、默認python3、ipython3、pip的路徑
? ? name@host:~$ which python
? ? /usr/bin/python
? ? name@host:~$ which python3
? ? /usr/bin/python3
? ? name@host:~$ which pip
? ? /usr/local/bin/pip
? ? name@host:~$ which pip3
? ? /usr/local/bin/pip3
? ? name@host:~$ which ipython3
? ? /usr/local/bin/ipython3
? ? name@host:~$ which ipython
? ? /usr/local/bin/ipyth
2、安裝之后的路徑
? ? /usr/local/python3.7/bin/pip3
? ? /usr/local/python3.7/bin/pip3.7
? ? /usr/local/python3.7/bin/python3
? ? /usr/local/python3.7/bin/python3.7
? ??
3、編譯安裝python3.7
? ? 參考鏈接:https://ywnz.com/linuxjc/3159.html
? ? https://www.jianshu.com/p/7d32fba1121a
? ? 官網下載:https://www.python.org/downloads/ ?file中選擇 Gzipped source tarball
? ? 比如:壓縮包名字是Python-3.7.0.tgz
? ? 解壓:
? ? ? ? sudo tar -xzf Python-3.7.0.tgz
? ? ? ? 可以 -C /opt/ 指定解壓路徑
? ? 編譯
? ? ? ? cd Python-3.7.0
? ? ? ? ./configure --prefix=/usr/local/python3.6 --enable-optimization
? ? ? ? --prefix 是預期安裝目錄,
? ? ? ? --enable-optimizations
? ? ? ? 是優化選項(LTO,PGO 等)加上這個 flag 編譯后,性能有 10% 左右的優化(如果沒記錯的話),但是這會明顯的增加編譯時間。不過關于 LTO 和 PGO 其實不在今天文章的討論范圍內,建議感興趣的可以看看
? ? ? ? GCC 中 LTO 的具體實現https://gcc.gnu.org/onlinedocs/gccint/LTO-Overview.html
? ? 安裝
? ? ? ? sudo make
? ? ? ? sudo make install
? ? 報錯以及解決
? ? ? ? 1. ?configure: error:in ‘路徑名’:
? ? ? ? ? ? no acceptable C compiler found in $path
? ? ? ? ? ? 解決:
? ? ? ? ? ? sudo apt-get upgrade
? ? ? ? ? ? sudo apt-get install build-essential
? ? ? ? 2. ?Python build finished successfully!
? ? ? ? ? ? The necessary bits to build these optional modules were not found:
? ? ? ? ? ? _ctypes
? ? ? ? 3. ?zipimport.ZipImportError: can't decompress data; zlib not available
? ? ? ? ? ? 解決: sudo apt install zlib*
? ? ? ? ? ? 參考:https://blog.csdn.net/blueheart20/article/details/72827666
? ? ? ? 4. ?ModuleNotFoundError: No module named '_ctypes'
? ? ? ? ? ? Makefile:1130: recipe for target 'install' failed
? ? ? ? ? ? make: *** [install] Error 1
? ? ? ? ? ? 解決:
? ? ? ? ? ? 解決:安裝模塊
? ? ? ? ? ? sudo apt-get update
? ? ? ? ? ? sudo apt dist-upgrade
? ? ? ? ? ? sudo apt install build-essential libncursesw5-dev libgdbm-dev libc6-dev
? ? ? ? ? ? sudo apt install libssl-dev openssl
? ? ? ? ? ? sudo apt install libffi-dev
? ? ? ? ? ? ---------------------
? ? ? ? ? ? 原文:https://blog.csdn.net/wang725/article/details/79905612
? ? ? ? ? ? 參考鏈接:http://www.cnblogs.com/abeen/p/9355389.html
4、安裝完成
?
? ? The directory '/home/name/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
? ? The directory '/home/name/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
? ? Looking in links: /tmp/tmp4crntzmm
? ? Collecting setuptools
? ? Collecting pip
? ? Installing collected packages: setuptools, pip
? ? Successfully installed pip-19.0.3 setuptools-40.8.0
鏈接處理
? ? 建立軟連接:
? ? ? ? ln -s /usr/local/python3.7/bin/python3 ?/usr/bin/python3
? ? ? ? 這樣建立之后,pip3 也會自動配置為python3.7的
? ? 下面的問題出現后,將/usr/bin/python3有恢復成了原來的。
? ? ? ? 建立了python3.7的軟連接
? ? ? ? ? ? ln -s /usr/local/python3.7/bin/python3 ?/usr/bin/python3
? ? ? ? 建立了pip3.7的軟連接
? ? ? ? ? ? sudo ln -s ?/usr/local/python3.7/bin/pip3 ? ?/usr/local/bin/pip3.7
? ? 對于ipython3
? ? ? ? 1.查看到 ipython3 命令在是 /usr/local/bin/ipython3
? ? ? ? 2.cat /usr/local/bin/ipython3
? ? ? ? ? ? 內容如下
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from IPython import start_ipython
if __name__ == '__main__':
? ? sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(start_ipython())
? ? ? ? ? ?復制一份命名為 /usr/local/bin/ipython3.7
? ? ? ? ? ?打開,將第一行改為 #!/usr/bin/python3.7
? ? ? ? ? ?試啟動:
? ? ? ? ? ? ? ? ipython3.7
? ? ? ? ? ? ? ? 報錯
? ? ? ? ? ? ? ? ? ? Traceback (most recent call last):
? ? ? ? ? ? ? ? ? ? File "/usr/local/bin/ipython3.7", line 7, in
? ? ? ? ? ? ? ? ? ? from IPython import start_ipython
? ? ? ? ? ? ? ? ? ? ModuleNotFoundError: No module named 'IPython'
? ? ? ? ? ? ? ? 安裝 sudo pip3.7 search ?ipython
? ? ? ? ? ? ? ? 成功
ipython3.7
/usr/local/python3.7/lib/python3.7/site-packages/IPython/core/history.py:226: UserWarning: IPython History requires SQLite, your history will not be saved
warn("IPython History requires SQLite, your history will not be saved")
Python 3.7.3 (default, May 20 2019, 15:29:59)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.5.0 -- An enhanced Interactive Python. Type '?' for help.
? ? 這樣 python3.7 就是python3.7的了
? ? 這樣 pip3.7 就是python3.7的了
5、系統問題:
? ? 1.執行apt update 時報錯, 因為python版本替換了
? ? ? ? 報錯如下:
? ? ? ? ? ? name@host:~$ sudo apt update
? ? ? ? ? ? 命中:1 http://archive.ubuntukylin.com:10006/ubuntukylin xenial InRelease
? ? ? ? ? ? 命中:2 http://archive.canonical.com/ubuntu bionic InRelease
? ? ? ? ? ? 命中:3 http://mirrors.aliyun.com/ubuntu bionic InRelease
? ? ? ? ? ? 命中:4 http://mirrors.aliyun.com/ubuntu bionic-security InRelease
? ? ? ? ? ? 獲取:5 https://deb.opera.com/opera-stable stable InRelease [2,591 B]
? ? ? ? ? ? 已下載 2,591 B,耗時 2秒 (1,552 B/s)
? ? ? ? ? ? Traceback (most recent call last):
? ? ? ? ? ? File "/usr/lib/cnf-update-db", line 8, in
? ? ? ? ? ? from CommandNotFound.db.creator import DbCreator
? ? ? ? ? ? ModuleNotFoundError: No module named 'CommandNotFound'
? ? ? ? ? ? 正在讀取軟件包列表... 完成
? ? ? ? ? ? E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi'
? ? ? ? ? ? E: Sub-process returned an error code
? ? ? 同時ubuntu默認終端打不開,還是因為python的版本替換
? ? ? 解決:將/usr/bin/python3下的軟連接恢復成原來的。
? ? 2.出現問題:
? ? ? ? E: 無法修正錯誤,因為您要求某些軟件包保持現狀,就是它們破壞了軟件包間的依賴關系。
? ? ? 原因:有 1 個軟件包沒有被完全安裝或卸載。
? ? ? 解決: sudo apt --fix-broken install
6、最后sudo apt autoremove清除多余的包
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
