简体   繁体   English

Python 虚拟环境未在正确目录中安装软件包(python)

[英]Python virtual environment not installing packages in correct directory (python)

I have set up a virtual environment correctly have activated it and when I do "which python" it tells me the correct directory, but when I do pip install in the venv it installs the package in the default directory of the mac and not in my venv.我已经正确设置了一个虚拟环境并激活了它,当我执行“which python”时,它会告诉我正确的目录,但是当我在 venv 中安装 pip 时,它会将 package 安装在 mac 的默认目录中,而不是我的venv。 I have tried using pycharm and installing packages with that, but it happens the same thing.我曾尝试使用 pycharm 并使用它安装软件包,但它发生了同样的事情。 Edit: Following I will do a walkthru of my steps, first I did python3 -m venv /path/to/new/virtual/environment , then I did source env/bin/activate , then I did which python and I got the intended directory, afterwards I did pip3 install numpy and I saw the installation process, then I did pip list and numpy was not there, I checked the directory manually and it still was not there.编辑:接下来我将完成我的步骤,首先我做了python3 -m venv /path/to/new/virtual/environment ,然后我做了source env/bin/activate ,然后我做which python ,我得到了预期目录,之后我做了pip3 install numpy并看到了安装过程,然后我做了pip list和 numpy 不存在,我手动检查了目录仍然不存在。 I retried all the same thing with pycharm with the same results.我用 pycharm 重试了所有相同的事情,结果相同。

Follow these steps in order -按顺序执行以下步骤 -

In your current working directory在您当前的工作目录中

python3 -m venv venv
source venv/bin/activate
(venv) pip3 install library_name

To check if libraries were properly installed or not -检查库是否正确安装 -

(venv) pip3 freeze

and check if your installed libraries is displayed on the terminal screen or not.并检查您安装的库是否显示在终端屏幕上。

To deactivate the virtual environment -要停用虚拟环境 -

(venv) deactivate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM