簡要
最近在學習python web,經常需要搭建不同環境,為了更好的去使用,并且不污染原本的python環境,我們一般都會選擇去建立一個虛拟的環境來運作一類代碼。
例如flask的獨立一個虛拟環境,Django的又是另外一個虛拟環境。
win10下建立虛拟環境,我們通常需要使用python中的virtualenv來進行建立,但是常常都是出現這麼一個情況。
相信很多小夥伴都遇到過這種問題,今天我們就來解決這個小問題!!!
前提
首先我們要确定我們的電腦已經安裝了python,并且已經配置了對應的環境變量。
示範的電腦使用的是Anaconda,可能有的小夥伴會說,可以直接去Anaconda的那個指令提示符使用,很簡單,不用這麼麻煩。
可小白是一個對代碼很強迫的人,遇見問題就要去解決掉,而且一些小夥伴也會有直接和小白另外一台電腦一樣的,直接安裝了python環境。
我們確定了自己的電腦安裝了python環境和配置環境變量後就可以開始正式操作起來了!
開搞
先退出python
使用"exit()"退出
C:\Users\MZ>python
Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated. Libraries may fail to load. To activate this environment
please see https://conda.io/activation
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
C:\Users\MZ>
1、為了確定一次安裝完成,我們需要先去確定我們的環境中沒有virtualenv
使用管理者運作cmd
插播一個pip環境變量的添加
打開發現anaconda沒有給我們配置pip的環境變量,無法在win10的cmd中直接運作
我們要先找到我們安裝python(anaconda)的路徑
找到script檔案夾,複制其路徑,在環境變量中進行一個pip的環境變量添加
(—複制的路徑最後加一個\—)
# 路徑:
C:\ProgramData\Anaconda3\Scripts\
建議在系統變量中添加:
回到正題
檢視已經安裝的包(可以不檢視直接下一步)
pip list
C:\WINDOWS\system32>pip list
Package Version
---------------------------------- -------------------
alabaster 0.7.12
anaconda-client 1.7.2
anaconda-navigator 1.10.0
anaconda-project 0.8.3
appdirs 1.4.4
argh 0.26.2
argon2-cffi 20.1.0
asn1crypto 1.4.0
astroid 2.4.2
astropy 4.0.2
async-generator 1.10
atomicwrites 1.4.0
attrs 20.3.0
autopep8 1.5.4
Babel 2.8.1
backcall 0.2.0
backports.functools-lru-cache 1.6.1
backports.shutil-get-terminal-size 1.0.0
backports.tempfile 1.0
backports.weakref 1.0.post1
bcrypt 3.2.0
beautifulsoup4 4.9.3
bitarray 1.6.1
bkcharts 0.2
bleach 3.2.1
bokeh 2.2.3
boto 2.49.0
Bottleneck 1.3.2
brotlipy 0.7.0
certifi 2020.6.20
cffi 1.14.3
chardet 3.0.4
click 7.1.2
cloudpickle 1.6.0
clyent 1.2.2
colorama 0.4.4
comtypes 1.1.7
conda 4.9.2
conda-build 3.20.5
conda-package-handling 1.7.2
conda-verify 3.4.2
contextlib2 0.6.0.post1
cryptography 3.1.1
cycler 0.10.0
Cython 0.29.21
cytoolz 0.11.0
dask 2.30.0
decorator 4.4.2
defusedxml 0.6.0
diff-match-patch 20200713
distlib 0.3.1
distributed 2.30.1
docutils 0.16
entrypoints 0.3
et-xmlfile 1.0.1
fastcache 1.1.0
filelock 3.0.12
flake8 3.8.4
Flask 1.1.2
fsspec 0.8.3
future 0.18.2
gevent 20.9.0
glob2 0.7
greenlet 0.4.17
h5py 2.10.0
HeapDict 1.0.1
html5lib 1.1
idna 2.10
imageio 2.9.0
imagesize 1.2.0
importlib-metadata 2.0.0
iniconfig 1.1.1
intervaltree 3.1.0
ipykernel 5.3.4
ipython 7.19.0
ipython-genutils 0.2.0
ipywidgets 7.5.1
isort 5.6.4
itsdangerous 1.1.0
jdcal 1.4.1
jedi 0.17.1
Jinja2 2.11.2
joblib 0.17.0
json5 0.9.5
jsonschema 3.2.0
jupyter 1.0.0
jupyter-client 6.1.7
jupyter-console 6.2.0
jupyter-core 4.6.3
jupyterlab 2.2.6
jupyterlab-pygments 0.1.2
jupyterlab-server 1.2.0
keyring 21.4.0
kiwisolver 1.3.0
lazy-object-proxy 1.4.3
libarchive-c 2.9
llvmlite 0.34.0
locket 0.2.0
lxml 4.6.1
MarkupSafe 1.1.1
matplotlib 3.3.2
mccabe 0.6.1
menuinst 1.4.16
mistune 0.8.4
mkl-fft 1.2.0
mkl-random 1.1.1
mkl-service 2.3.0
mock 4.0.2
more-itertools 8.6.0
mpmath 1.1.0
msgpack 1.0.0
multipledispatch 0.6.0
navigator-updater 0.2.1
nbclient 0.5.1
nbconvert 6.0.7
nbformat 5.0.8
nest-asyncio 1.4.2
networkx 2.5
nltk 3.5
nose 1.3.7
notebook 6.1.4
numba 0.51.2
numexpr 2.7.1
numpy 1.19.2
numpydoc 1.1.0
olefile 0.46
openpyxl 3.0.5
packaging 20.4
pandas 1.1.3
pandocfilters 1.4.3
paramiko 2.7.2
parso 0.7.0
partd 1.1.0
path 15.0.0
pathlib2 2.3.5
pathtools 0.1.2
patsy 0.5.1
pep8 1.7.1
pexpect 4.8.0
pickleshare 0.7.5
Pillow 8.0.1
pip 20.2.4
pkginfo 1.6.1
pluggy 0.13.1
ply 3.11
prometheus-client 0.8.0
prompt-toolkit 3.0.8
psutil 5.7.2
py 1.9.0
pycodestyle 2.6.0
pycosat 0.6.3
pycparser 2.20
pycurl 7.43.0.6
pydocstyle 5.1.1
pyflakes 2.2.0
Pygments 2.7.2
pylint 2.6.0
PyNaCl 1.4.0
pyodbc 4.0.0-unsupported
pyOpenSSL 19.1.0
pyparsing 2.4.7
pyreadline 2.1
pyrsistent 0.17.3
PySocks 1.7.1
pytest 0.0.0
python-dateutil 2.8.1
python-jsonrpc-server 0.4.0
python-language-server 0.35.1
pytz 2020.1
PyWavelets 1.1.1
pywin32 227
pywin32-ctypes 0.2.0
pywinpty 0.5.7
PyYAML 5.3.1
pyzmq 19.0.2
QDarkStyle 2.8.1
QtAwesome 1.0.1
qtconsole 4.7.7
QtPy 1.9.0
regex 2020.10.15
requests 2.24.0
rope 0.18.0
Rtree 0.9.4
ruamel-yaml 0.15.87
scikit-image 0.17.2
scikit-learn 0.23.2
scipy 1.5.2
seaborn 0.11.0
Send2Trash 1.5.0
setuptools 50.3.1.post20201107
simplegeneric 0.8.1
singledispatch 3.4.0.3
sip 4.19.13
six 1.15.0
snowballstemmer 2.0.0
sortedcollections 1.2.1
sortedcontainers 2.2.2
soupsieve 2.0.1
Sphinx 3.2.1
sphinxcontrib-applehelp 1.0.2
sphinxcontrib-devhelp 1.0.2
sphinxcontrib-htmlhelp 1.0.3
sphinxcontrib-jsmath 1.0.1
sphinxcontrib-qthelp 1.0.3
sphinxcontrib-serializinghtml 1.1.4
sphinxcontrib-websupport 1.2.4
spyder 4.1.5
spyder-kernels 1.9.4
SQLAlchemy 1.3.20
statsmodels 0.12.0
sympy 1.6.2
tables 3.6.1
tblib 1.7.0
terminado 0.9.1
testpath 0.4.4
threadpoolctl 2.1.0
tifffile 2020.10.1
toml 0.10.1
toolz 0.11.1
tornado 6.0.4
tqdm 4.50.2
traitlets 5.0.5
typing-extensions 3.7.4.3
ujson 4.0.1
unicodecsv 0.14.1
urllib3 1.25.11
virtualenv 20.4.6
watchdog 0.10.3
wcwidth 0.2.5
webencodings 0.5.1
Werkzeug 1.0.1
wheel 0.35.1
widgetsnbextension 3.5.1
win-inet-pton 1.1.0
win-unicode-console 0.5
wincertstore 0.2
wrapt 1.11.2
xlrd 1.2.0
XlsxWriter 1.3.7
xlwings 0.20.8
xlwt 1.3.0
xmltodict 0.12.0
yapf 0.30.0
zict 2.0.0
zipp 3.4.0
zope.event 4.5.0
zope.interface 5.1.2
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
C:\WINDOWS\system32>
解除安裝原有的virtualenv
anaconda自帶了第三方庫,所有會比較多,我麼可以直接運作指令,并不影響
- 管理者下運作聰明的
運作情況如下# 管理者模式打開cmd,解除安裝了之前在普通使用者權限下安裝的virtualenv和virtualenvwrapper # 代碼如下 pip uninstall virtualenv pip uninstall virtualenvwrapper-win
C:\WINDOWS\system32>pip uninstall virtualenv Found existing installation: virtualenv 20.4.6 Uninstalling virtualenv-20.4.6: Would remove: c:\programdata\anaconda3\lib\site-packages\virtualenv-20.4.6.dist-info\* c:\programdata\anaconda3\lib\site-packages\virtualenv\* c:\programdata\anaconda3\scripts\virtualenv.exe Proceed (y/n)? Your response ('') was not one of the expected responses: y, n Proceed (y/n)? Your response ('') was not one of the expected responses: y, n Proceed (y/n)? pip uninstall virtualenvwrapper-win Your response ('pip uninstall virtualenvwrapper-win') was not one of the expected responses: y, n Proceed (y/n)? y Successfully uninstalled virtualenv-20.4.6 C:\WINDOWS\system32>pip uninstall virtualenvwrapper-win WARNING: Skipping virtualenvwrapper-win as it is not installed. C:\WINDOWS\system32>
重新安裝
- 安裝一定要按照步驟去安裝,不然可能還是會失敗
- 先安裝virtualenv
- 然後安裝virtualenvweapper-win
# 安裝步驟 pip install virtualenv pip install virtualenvwrapper-win # 安裝完成即可
# 安裝效果 C:\Users\MZ>pip install virtualenv Collecting virtualenv Downloading virtualenv-20.4.7-py2.py3-none-any.whl (7.2 MB) |████████████████████████████████| 7.2 MB 720 kB/s Requirement already satisfied: filelock<4,>=3.0.0 in c:\programdata\anaconda3\lib\site-packages (from virtualenv) (3.0.12) Requirement already satisfied: six<2,>=1.9.0 in c:\programdata\anaconda3\lib\site-packages (from virtualenv) (1.15.0) Requirement already satisfied: distlib<1,>=0.3.1 in c:\programdata\anaconda3\lib\site-packages (from virtualenv) (0.3.1) Requirement already satisfied: appdirs<2,>=1.4.3 in c:\programdata\anaconda3\lib\site-packages (from virtualenv) (1.4.4) Installing collected packages: virtualenv Successfully installed virtualenv-20.4.7 C:\Users\MZ>pip install virtualenvwrapper-win Collecting virtualenvwrapper-win Downloading virtualenvwrapper-win-1.2.6.tar.gz (21 kB) Requirement already satisfied: virtualenv in c:\programdata\anaconda3\lib\site-packages (from virtualenvwrapper-win) (20.4.7) Requirement already satisfied: appdirs<2,>=1.4.3 in c:\programdata\anaconda3\lib\site-packages (from virtualenv->virtualenvwrapper-win) (1.4.4) Requirement already satisfied: six<2,>=1.9.0 in c:\programdata\anaconda3\lib\site-packages (from virtualenv->virtualenvwrapper-win) (1.15.0) Requirement already satisfied: distlib<1,>=0.3.1 in c:\programdata\anaconda3\lib\site-packages (from virtualenv->virtualenvwrapper-win) (0.3.1) Requirement already satisfied: filelock<4,>=3.0.0 in c:\programdata\anaconda3\lib\site-packages (from virtualenv->virtualenvwrapper-win) (3.0.12) Building wheels for collected packages: virtualenvwrapper-win Building wheel for virtualenvwrapper-win (setup.py) ... done Created wheel for virtualenvwrapper-win: filename=virtualenvwrapper_win-1.2.6-py3-none-any.whl size=18614 sha256=631197a1ab352bcc0535e646fbe77235a287989a8de8a01e5ebcebb03daf6c43 Stored in directory: c:\users\mz\appdata\local\pip\cache\wheels\66\25\f7\f4b3539b1cc86289c4e24e637c09a39f8f2ab6de61928f0be1 Successfully built virtualenvwrapper-win Installing collected packages: virtualenvwrapper-win Successfully installed virtualenvwrapper-win-1.2.6 # 這樣就安裝完成啦
測試運作情況
# cd 到一個空的檔案夾或者其他自己想存儲的位置進行一個建立 G:\>virtualenv flask_env01 created virtual environment CPython3.8.5.final.0-64 in 5695ms creator CPython3Windows(dest=G:\flask_env01, clear=False, no_vcs_ignore=False, global=False) seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=C:\Users\MZ\AppData\Local\pypa\virtualenv) added seed packages: pip==21.1.2, setuptools==56.0.0, wheel==0.36.2 activators BashActivator,BatchActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator G:\>
在插播一個pip國内源的廣告
為了更好的下載下傳我們的庫,我們一般都會使用國内的鏡像源,為了更好的去運作代碼,并且節省我們的時間
鏡像源的方法已經寫在了另一個文章中,就不再重新去寫了,感興趣的小夥伴可以去檢視一下,方式很多,但是建議直接設定好,友善下次的使用。
pip國内源
喜歡的點贊、評論收藏三連哦!!!!
親測python環境下有效!!!!
有其他的小問題也可以評論區回複哦
關注小白不碰壁、不迷路
win10安裝這些庫什麼的可以關注小白,小白日常碰壁哦!
隻要小白遇見的小問題都會去解決,并且給大家提供解決方法,避免大家也日常去碰壁!!!
PowerShellActivator,PythonActivator,XonshActivator
G:>
### 在插播一個pip國内源的廣告
為了更好的下載下傳我們的庫,我們一般都會使用國内的鏡像源,為了更好的去運作代碼,并且節省我們的時間
鏡像源的方法已經寫在了另一個文章中,就不再重新去寫了,感興趣的小夥伴可以去檢視一下,方式很多,但是建議直接設定好,友善下次的使用。
**[pip國内源](https://blog.csdn.net/weixin_47929954/article/details/113656265)**
喜歡的點贊、評論收藏三連哦!!!!
親測python環境下有效!!!!
### 有其他的小問題也可以評論區回複哦
## 關注小白不碰壁、不迷路
win10安裝這些庫什麼的可以關注小白,小白日常碰壁哦!
隻要小白遇見的小問題都會去解決,并且給大家提供解決方法,避免大家也日常去碰壁!!!