網(wǎng)站首頁 編程語言 正文
centos自帶了python3.6.8的python, 然后我想安裝更高版本的python,比如python3.8.8, 可以自行搜索一下安裝方法,有很多(如果安裝后的python出現(xiàn)No module named ‘_ssl’ 這個報(bào)錯,請拉到最后看)
值得注意的是,安裝好之后,由于python3,pip3軟鏈接指向的是python3.6的
這里有2個思路,一個是設(shè)置軟鏈接python,pip對應(yīng)python3.8.8
# /usr/local/python 這個是我python3.8.8的安裝目錄,這樣設(shè)置之后,python指向的就是python3.8.8,pip安裝的也是python3.8.8的
ln -s /usr/local/python/bin/python3 /usr/bin/python
ln -s /usr/local/python/bin/pip3 /usr/bin/pip
另一個思路是將原來python3,pip3的軟鏈接刪掉, 重新建立鏈接
rm -rf /usr/bin/python3
rm -rf /usr/bin/pip3
# 再重新把python3的軟鏈接指向python3.8.8的
ln -s /usr/local/python/bin/python3 /usr/bin/python3
ln -s /usr/local/python/bin/pip3 /usr/bin/pip3
2種方式?jīng)]有優(yōu)劣之分,如果安裝很多版本的python的話,比如python3.6, python3.7,python3.8等等, 那么建議每個python版本創(chuàng)建不同的軟鏈接,比如python3.6指向的就是python3.6, python3.7指向的就是python3.7…
安裝好python之后,安裝virtualenv 和 virtualenvwrapper
pip install virtualenv
pip install virtualenvwrapper
如果安裝virtualenvwrapper報(bào)錯如下
Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Collecting virtualenvwrapper
Using cached http://mirrors.cloud.aliyuncs.com/pypi/packages/c1/6b/2f05d73b2d2f2410b48b90d3783a0034c26afa534a4a95ad5f1178d61191/virtualenvwrapper-4.8.4.tar.gz (334 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [35 lines of output]
WARNING: The wheel package is not available.
WARNING: The repository located at mirrors.cloud.aliyuncs.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host mirrors.cloud.aliyuncs.com'.
ERROR: Could not find a version that satisfies the requirement pbr (from versions: none)
ERROR: No matching distribution found for pbr
Traceback (most recent call last):
File "/usr/local/python/lib/python3.8/site-packages/setuptools/installer.py", line 128, in fetch_build_egg
subprocess.check_call(cmd)
File "/usr/local/python/lib/python3.8/subprocess.py", line 364, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/local/python/bin/python3.8', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/tmp/tmp97rcd69z', '--quiet', '--index-url', 'http://mirrors.cloud.aliyuncs.com/pypi/simple/', 'pbr']' returned non-zero exit status 1.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-q_8kre6_/virtualenvwrapper_564bbfde4dde45cb9571ba4b69c38f83/setup.py", line 5, in <module>
setup(
File "/usr/local/python/lib/python3.8/site-packages/setuptools/__init__.py", line 164, in setup
_install_setup_requires(attrs)
File "/usr/local/python/lib/python3.8/site-packages/setuptools/__init__.py", line 159, in _install_setup_requires
dist.fetch_build_eggs(dist.setup_requires)
File "/usr/local/python/lib/python3.8/site-packages/setuptools/dist.py", line 699, in fetch_build_eggs
resolved_dists = pkg_resources.working_set.resolve(
File "/usr/local/python/lib/python3.8/site-packages/pkg_resources/__init__.py", line 779, in resolve
dist = best[req.key] = env.best_match(
File "/usr/local/python/lib/python3.8/site-packages/pkg_resources/__init__.py", line 1064, in best_match
return self.obtain(req, installer)
File "/usr/local/python/lib/python3.8/site-packages/pkg_resources/__init__.py", line 1076, in obtain
return installer(requirement)
File "/usr/local/python/lib/python3.8/site-packages/setuptools/dist.py", line 758, in fetch_build_egg
return fetch_build_egg(self, req)
File "/usr/local/python/lib/python3.8/site-packages/setuptools/installer.py", line 130, in fetch_build_egg
raise DistutilsError(str(e)) from e
distutils.errors.DistutilsError: Command '['/usr/local/python/bin/python3.8', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/tmp/tmp97rcd69z', '--quiet', '--index-url', 'http://mirrors.cloud.aliyuncs.com/pypi/simple/', 'pbr']' returned non-zero exit status 1.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
執(zhí)行pip install pbr
即可
然后找一個目錄放虛擬環(huán)境的文件,我這里放在home目錄下,cd /home之后
mkdir .virtualenvs
然后在root目錄下,vim .bashrc 在最下面添加如下
# 指定virtualenvwrapper執(zhí)行的python版本
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
# 指定virtualenv的路徑
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/python/bin/virtualenv
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/python/bin/virtualenvwrapper.sh
然后source ~/.bashrc 激活
再次說明一下,/usr/loacl/python 是我的python3.8.8的安裝目錄
Python-3.8.8是解壓后的,python是安裝后的目錄
如果執(zhí)行 mkvirtualenv django報(bào)以下錯的話
No module named '_ssl'
請參考https://blog.csdn.net/sinat_34149445/article/details/105387170
需要安裝依賴,修改解壓后的Python-3.8.8/Modules/Setup 文件,然后重新編譯安裝python3.8.8, 然后重新安裝virtualenv,virtualenvwrapper, source ~/.bashrc
原文鏈接:https://blog.csdn.net/weixin_44936542/article/details/126062646
相關(guān)推薦
- 2022-07-30 jQuery?UI工具提示框部件Tooltip?Widget_jquery
- 2022-05-31 python中三種輸出格式總結(jié)(%,format,f-string)_python
- 2024-03-14 docker創(chuàng)建自定義網(wǎng)絡(luò)
- 2022-07-30 Redis?keys命令的具體使用_Redis
- 2022-04-01 Python?eval()?函數(shù)看這一篇就夠了_python
- 2022-11-05 swift語言AutoreleasePool原理及使用場景_Swift
- 2022-04-09 MFC模擬實(shí)現(xiàn)自定義消息發(fā)送_C 語言
- 2022-08-29 Python使用re模塊實(shí)現(xiàn)正則表達(dá)式操作指南_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支