Python环境常见问题解决⽅案
如下列举了python使⽤过程中环境配置容易出现的⼀些问题,供⼩伙伴们参考:
1、pip版本升级
在安装⼀些依赖包时,会提⽰pip版本太低,需要升级
You are using pip version 19.0.3, however version 19.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
于是使⽤pip install --upgrade pip进⾏升级。但是解决不了,弄了好久,后⾯到⽅法了
python -m pip install --upgrade pip
2、安装numpy时,总是会提⽰:
Found existing installation: numpy 1.8.0rc1
Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it
which would lead to only a partial uninstall.
如图:
alicedeMacBook-Pro:~ alice$ pip3 install numpy
Requirement already satisfied: numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (1.8.0rc1)
alicedeMacBook-Pro:~ alice$ pip3 install numpy --upgrade
Collecting numpy
Using cached /packages/a6/6f/cb20ccd8f0f8581e0e090775c0e3c3e335b037818416e6fa945d924397d2/numpy-1.16.2-cp37-cp37m Installing collected packages: numpy
Found existing installation: numpy 1.8.0rc1
Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninsta
selected手表使⽤sudo pip3 install numpy --upgrade试图升级,仍然失败:
⽹上搜了好久,最后使⽤这句:sudo pip install numpy --ignore-installed numpy
强制卸载更新,成功了
alicedeMacBook-Pro:~ alice$ sudo pip3 install numpy --ignore-installed numpy
Password:
The directory '/Users/alice/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the per The directory '/Users/alice/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissio Collecting numpy
Downloading /packages/a6/6f/cb20ccd8f0f8581e0e090775c0e3c3e335b037818416e6fa945d924397d2/numpy-1.16.2-cp37-cp37m    100% |████████████████████████████████| 13.9MB 81kB/s
Installing collected packages: numpy
Successfully installed numpy-1.16.2
3、Mac上因为有⾃带的2.7,通常⼜会安装⼀个3.7,多个python版本,容易导致numpy的版本冲突。经常会出现这个提⽰:
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/core/multiarray.so
python安装教程mac
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/core/__init__.py", line 40, in <module>
from . import multiarray
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/
numpy/core/multiarray.so, 2): Symbol not found: _PyBuffer_  Referenced from: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/core/multiarray.so
ostrich发音
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/core/multiarray.so
原因是numpy冲突,安装⽂件有问题,解决办法是删除掉numpy安装包重新安装即可。
4、安装的依赖库⽐如pillow、matplotlib在python程序运⾏时不到,其中⼀个原因可能是因为安装的库不在对应python⽬录下,Mac的
多个python版本导致
安装python3之后,库⾥⾯既会同时有两个版本,对应的区分是pip3、pip,有什么区别呢?
⽐如在终端⾥使⽤pip install XXX ,则新安装的库会放在⽬录 :python2.7/site-packages
使⽤pip3 install XXX ,则新安装的库会放在⽬录:python3.6/site-packages
因此,在安装依赖库的包时应注意⾃⼰要使⽤的环境是哪个版本的python环境,正确的使⽤pip3或pip
5、在使⽤PIL依赖库时,提⽰:ModuleNotFoundError: No module named 'PIL'
Traceback (most recent call last):compare means是什么意思
File "/Users/alice/PycharmProjects/untitled/checkxy.py", line 4, in <module>
from PIL import Image,ImageFont,ImageDraw
ModuleNotFoundError: No module named 'PIL'
使⽤pip3 install PIL安装时,仍然报错提⽰:No matching distribution found for PIL
alicedembp:~ alice$ pip3 install PIL
Collecting PIL
Could not find a version that satisfies the requirement PIL (from versions: ) No matching distribution f
颜的英文大全ound for PIL
后来⽤了:pip3 install pillow解决。
6、在使⽤pip3 install matplotlib,安装matplotlib时,出现
什么叫做原码反码补码You are using pip version 10.0.1, however version 19.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.解决⽅法是:pip3 install --upgrade pip,

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。