对 python venv 和全局模块的不满 [英] frustrations over python venv and global modules
问题描述
几个月前我写了一个网页抓取编程,我让 python -m venv venv
做了一堆 pip 安装,检查并使用 pip list
,一切看起来都很好.
I wrote a web scraping programming a couple of months ago, which I had python -m venv venv
did a bunch of pip install, checked and doubled check with pip list
, everything looks fine.
今天我想再次抓取所以我用pip list
检查了我的source venv/bin/activate
,一切看起来都很好,只是没有这个模块那...
And today I wanna scrape again so I did my source venv/bin/activate
checked with pip list
, everything looks fine, and just keep having no module of this and that...
但是当我停用它时,它会退回到我全局安装的模块,我的程序运行得非常好.我简直不敢相信,所以我做到了:rm -rf venv
和python -m venv source venv/bin/activate pip install -r requirements.txt
一切都安装好了,用 pip list
检查,没有这个或那个模块.
But when I deactivated it, it falls back to my global installed modules, my program runs perfectly fine. I could't believe it so i did :
rm -rf venv
and
python -m venv source venv/bin/activate pip install -r requirements.txt
everything installed, check with pip list
, and no module of this or that.
任何人,请告诉我发生了什么?谢谢!
Anyone, please tell me what's happening? thank you!
推荐答案
确保使用的是什么 python 以及哪个 python 链接到当前 pip:
To ensure what python is being used and which python is linked to current pip:
which python
查看python 可执行文件在哪里(或者which python3
、which python3.7
等...)立>- 运行
python
显示python版本 pip -V
显示它所链接的 python- 使用
python -m pip list
确保pip链接到python python -m site
显示site-package
位于- 编写
python
并多次点击TAB
显示路径中可用的 python(取决于操作系统)
which python
to see where is the python executable (alternativelywhich python3
,which python3.7
, etc...)- running
python
show the version of python pip -V
shows the python to which it is linked- use
python -m pip list
to ensure the pip is linked to the python python -m site
shows were is thesite-package
located- writing
python
and hittingTAB
multiple times shows what pythons are available in the path (os dependent)
这更像是一种调试正在使用的 Python 的方法.
This is more of a way to debug which python is being used.
这篇关于对 python venv 和全局模块的不满的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!