简体   繁体   English

pip3 将模块安装到 python3 找不到的位置

[英]pip3 installs modules to location python3 can't find

I have pip3, installed via the yum install of python3-pip.我有 pip3,通过 python3-pip 的 yum install 安装。

I've done a pip3 global install of some modules I need, but python3 can't find them to import.我已经对我需要的一些模块进行了 pip3 全局安装,但是 python3 找不到要导入的模块。 After a little investigation I see that pip3 installed the modules to /usrlib/python3.6/site-packages/pip/_vendor/经过一番调查,我看到 pip3 将模块安装到 /usrlib/python3.6/site-packages/pip/_vendor/

The problem is that python3 doesn't seem to know to look at pip/_vendor, it only finds modules directly installed under site-package.问题是python3似乎不知道看pip/_vendor,它只找到直接安装在site-package下的模块。 If I just copy the modules from .../site-package/pip/_vendor to .../site-package everything works fine.如果我只是将模块从 .../site-package/pip/_vendor 复制到 .../site-package 一切正常。

The issue doesn't appear to be related to file permissions or ability to read the modules.该问题似乎与文件权限或读取模块的能力无关。

I'm wondering how I configure either pip to install directly to site-package or python3 to understand how to look in the pip/_vendor location.我想知道如何配置 pip 以直接安装到站点包或 python3 以了解如何查看 pip/_vendor 位置。

I'm configuring this all with ansible and would like as module an option as possible.我正在用 ansible 配置这一切,并希望尽可能作为模块选项。 For instance I could manually use an argument to tell pip3 to install to the folder I want, but I don't want to hardcode the exact site-package directory if I don't have to.例如,我可以手动使用一个参数来告诉 pip3 安装到我想要的文件夹,但如果我不需要,我不想硬编码确切的站点包目录。

I recommend starting over with pip by downloading and running get-pip.py .我建议通过下载并运行get-pip.py重新开始使用pip This will not only install the latest version of pip , but it will also install packages to a Python-readable location (the version of Python you use to run get-pip.py ).这不仅会安装最新版本的pip ,还会将包安装到 Python 可读的位置(用于运行get-pip.py的 Python 版本)。

As an aside, I would avoid installing packages system-wide unless there is a specific need for them.顺便说一句,除非有特殊需要,否则我会避免在系统范围内安装软件包。 At the very least, you should be installing them as a regular user, and even better you should be using a virtualenv.至少,您应该以普通用户的身份安装它们,甚至更好的是您应该使用 virtualenv。

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

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