pycharm创建虚拟环境venv和添加依赖库package
1.创建虚拟环境
因为项⽬采⽤不同版本的python,所依赖的库的版本也不⼀样,为了避免版本冲突,为每⼀个项⽬每个python版本创建⼀个虚拟环境,环境中所使⽤的依赖库也是独⽴存在,不会被其他版本或其他项⽬的库影响。
(1)基于python版本创建虚拟环境
在pycharm的file-setting中选中project,然后点击project interpreter的右侧点击添加按钮
(2)输⼊基于哪个python版本创建虚拟环境,环境的路径选择项⽬路径下,点击ok就可以创建新的虚拟环境。
在项⽬路径下就有会⽣成⼀个venv路径 D:\Project\python\handson-ml-master\venv
项⽬的依赖库package保存在路径D:\Project\python\handson-ml-master\venv\Lib\site-packages下,是这个项⽬⼯程的依赖库。
2.pycharm添加依赖库package
(1)点击下图中+号按钮添加依赖库
(2)点击manager resposities,设置新的镜像
(3)设置下载库的⽹址镜像为⾖瓣镜像,原有的镜像太慢会出错
(4)加pip的配置⽂件,赋予权限否则会报不信任的错误
在C:\Users\baochunlei\AppData\Roaming⽬录下创建⽂件夹和⽂件pip\pip.ini,输⼊如下内容
python默认安装路径不加的话会出现如下错误
Non-zero exit code (1)
Try to run this command from the system terminal. Make sure that you use the correct version of 'pip' installed for your Python interpreter located at 'D:\Project\python\handson-ml-master\venv\'.
The repository located at pypi.douban 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 pypi.douban'.
Could not find a version that satisfies the requirement matplotlib (from versions: )
No matching distribution found for matplotlib
(5)输⼊需要添加的依赖包,⾃动检索到,后选择依赖包,然后点击安装
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论