[英]Activated virtual environment using incorrect Python executable
I am working on a project through PyCharm.我正在通过 PyCharm 开展一个项目。 When I started the project, the project interpreter was a newly created virtualenv located in my project folder at
/path/to/project_folder/venv
and using base interpreter /usr/bin/python3.6
.当我开始项目时,项目解释器是一个新创建的 virtualenv,位于我的项目文件夹中
/path/to/project_folder/venv
并使用基本解释器/usr/bin/python3.6
。
When working in PyCharm, the Python Console seems to be using the right venv/Python executable etc. Running os.system("which python")
returns /usr/bin/python
.在 PyCharm 中工作时,Python 控制台似乎正在使用正确的 venv/Python 可执行文件等。运行
os.system("which python")
返回/usr/bin/python
。
Next, I activate this venv through my terminal (on Ubuntu 18.04) using the command source /path/to/project_folder/venv/bin/activate
which works fine and shows me that it is activated with a (venv)
.接下来,我使用命令
source /path/to/project_folder/venv/bin/activate
通过我的终端(在 Ubuntu 18.04 上)激活这个 venv,它工作正常并显示它是用(venv)
激活的。 However, if I run which python
, it returns /home/user/anaconda3/bin/python
.但是,如果我运行
which python
,它会返回/home/user/anaconda3/bin/python
。
Why is this occurring?为什么会出现这种情况? How can I access the same Python interpreter from the PyCharm console through my Ubuntu terminal?
如何通过我的 Ubuntu 终端从 PyCharm 控制台访问相同的 Python 解释器?
Same happened to me in a specific project.在一个特定的项目中,我也遇到了同样的情况。
Symptoms:症状:
which python3
from bash is not taken from venv which python3
不是取自 venvCause:原因:
Solutions:解决方案:
Change PATH
is not the solution.更改
PATH
不是解决方案。 venv
script creates some other routes in various files. venv
脚本在各种文件中创建一些其他路由。
Note: Tested with python3 -m venv venv
注意:使用
python3 -m venv venv
测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.