在用anaconda,尤其是win下的时候,本地的python版本可能和虚拟环境中需要的python版本不同,而在虚拟环境中使用pip3安装包的时候,仍会出现版本是本地的python版本的情况,虽然并不是很清楚原因,不过记录并揣测一下。
1 (base) C:\Users\Renyi>conda create --name yolov3 python=3.7 2 Solving environment: done 3 4 5 ==> WARNING: A newer version of conda exists. <== 6 current version: 4.5.4 7 latest version: 4.6.8 8 9 Please update conda by running10 11 $ conda update -n base conda12 13 14 15 ## Package Plan ##16 17 environment location: C:\Users\Renyi\Anaconda3\envs\yolov318 19 added / updated specs:20 - python=3.721 22 23 The following packages will be downloaded:24 25 package | build26 ---------------------------|-----------------27 openssl-1.1.1b | he774522_1 5.7 MB28 setuptools-40.8.0 | py37_0 663 KB29 certifi-2019.3.9 | py37_0 155 KB30 wincertstore-0.2 | py37_0 13 KB31 wheel-0.33.1 | py37_0 57 KB32 python-3.7.2 | h8c8aaf0_10 17.7 MB33 ca-certificates-2019.1.23 | 0 158 KB34 pip-19.0.3 | py37_0 1.8 MB35 ------------------------------------------------------------36 Total: 26.3 MB37 38 The following NEW packages will be INSTALLED:39 40 ca-certificates: 2019.1.23-041 certifi: 2019.3.9-py37_042 openssl: 1.1.1b-he774522_143 pip: 19.0.3-py37_044 python: 3.7.2-h8c8aaf0_1045 setuptools: 40.8.0-py37_046 sqlite: 3.27.2-he774522_047 vc: 14.1-h0510ff6_448 vs2015_runtime: 14.15.26706-h3a45250_049 wheel: 0.33.1-py37_050 wincertstore: 0.2-py37_051 52 Proceed ([y]/n)? y53 54 55 Downloading and Extracting Packages56 openssl-1.1.1b | 5.7 MB | ############################################################################## | 100%57 setuptools-40.8.0 | 663 KB | ############################################################################## | 100%58 certifi-2019.3.9 | 155 KB | ############################################################################## | 100%59 wincertstore-0.2 | 13 KB | ############################################################################## | 100%60 wheel-0.33.1 | 57 KB | ############################################################################## | 100%61 python-3.7.2 | 17.7 MB | ############################################################################## | 100%62 ca-certificates-2019 | 158 KB | ############################################################################## | 100%63 pip-19.0.3 | 1.8 MB | ############################################################################## | 100%64 Preparing transaction: done65 Verifying transaction: done66 Executing transaction: done67 #68 # To activate this environment, use69 #70 # $ conda activate yolov371 #72 # To deactivate an active environment, use73 #74 # $ conda deactivate
这里我新建了一个python3.7的虚拟环境,提示中安装的是基于3.7的pip
1 (base) D:\PyCode\yolov3>conda activate yolov3 2 3 (yolov3) D:\PyCode\yolov3>python 4 Python 3.7.2 (default, Feb 21 2019, 17:35:59) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32 5 Type "help", "copyright", "credits" or "license" for more information. 6 >>> exit(0) 7 8 (yolov3) D:\PyCode\yolov3>pip3 install -U -r requirements.txt 9 Collecting numpy (from -r requirements.txt (line 3))10 Downloading https://files.pythonhosted.org/packages/ed/29/d97b6252591da5f8add0d25eecda296ea72729a0aad7998edba1981b47c8/numpy-1.16.2-cp36-cp36m-win_amd64.whl (11.9MB)11 0% | | 61kB 28kB/s eta 0:07:0012 Operation cancelled by user
接着我进入了刚创建完的虚拟环境,python是3.7.2版本的,然后我运行pip3来安装requirements.txt,里面有numpy,发现安装的版本是python3.6的
于是我终止了安装,并猜测,可能此时pip是更新过的,但pip3不是(未经验证) -- 试了一下用pip指令就是cp37的内容了,那应该就是将pip更新成了python3.7的,但pip3没有,用get-pip.py能将pip3也更新成python3.7版本的
不过总之尝试了若干次,我发现此时更新一下pip就好了,我的更新方法还是有get-pip.py
文件地址:
https://bootstrap.pypa.io/get-pip.py
参见:
1 (yolov3) D:\PyCode\yolov3>python get-pip.py 2 Collecting pip 3 Using cached https://files.pythonhosted.org/packages/d8/f3/413bab4ff08e1fc4828dfc59996d721917df8e8583ea85385d51125dceff/pip-19.0.3-py2.py3-none-any.whl 4 Installing collected packages: pip 5 Found existing installation: pip 19.0.3 6 Uninstalling pip-19.0.3: 7 Successfully uninstalled pip-19.0.3 8 Successfully installed pip-19.0.3 9 10 (yolov3) D:\PyCode\yolov3>pip3 install -U -r requirements.txt11 Collecting numpy (from -r requirements.txt (line 3))12 Downloading https://files.pythonhosted.org/packages/3a/3c/515afabfe4f29bfc0a67037efaf518c33d0076b32d22ba865241cee295c4/numpy-1.16.2-cp37-cp37m-win_amd64.whl (11.9MB)13 8% |██▌ | 962kB 6.6kB/s eta 0:27:35
虽然看起来就是把pip-19.0.3删了再装了一次,不过这个时候再装环境,就是python3.7下的numpy了