简体   繁体   English

将软件包安装到python虚拟环境中

[英]Installing packages into python virtual environment

I know this question sounds silly, but I can not find a detour in a short time. 我知道这个问题听起来很傻,但是我在短时间内找不到绕道而行。 I understand that to download packages into python you either use: 我知道您可以使用以下两种方式将软件包下载到python中:

pipenv install <package-name>

or 要么

pipenv install <wheel-name.whl>

Now, I want to install sklearn into pipenv environment so that I can later upload it to Amazone. 现在,我想将sklearn安装到pipenv环境中,以便以后可以将其上传到Amazone。 I tried to install sklearn using pipenv install sklearna and another using the wheel provided from https://www.lfd.uci.edu/~gohlke/pythonlibs/ . 我尝试使用pipenv install sklearna和另一个使用https://www.lfd.uci.edu/~gohlke/pythonlibs/提供的滚轮安装sklearn。 It's installed, but once I open the installed requirements using: 它已安装,但是一旦我使用以下方法打开安装的需求:

pipenv lock -r > requirements.txt

I got the following long name for sklearn: 我为sklearn取了以下长名:

-i https://pypi.org/simple
./sklearn_contrib_py_earth-0.1.0-cp36-cp36m-win_amd64.whl
joblib==0.14.0
numpy==1.17.4
pandas==0.25.3
python-dateutil==2.8.1
pytz==2019.3
scikit-learn==0.21.3
scipy==1.3.3
six==1.13.0

Why I don't get the same name as the one defined above, ie, the name of the package not it's wheel. 为什么我没有获得与上面定义的名称相同的名称,即包装的名称而不是轮子。

It's because you installed it from the .whl file instead of from pypi. 这是因为您是从.whl文件而不是从pypi安装的。

The requirements.txt lists the exact version of a package you have installed. requirements.txt列出了已安装的软件包的确切版本。 If it was to list something like: 如果要列出类似的内容:

sklearn==0.4.0

That would be incorrect as you installed your own version, which for all pip knows, could be a different package or version. 那是不正确的,因为您安装了自己的版本,所有小知识都知道这可能是不同的软件包或版本。

If you can't install sklearn from pypi then you will need to make sure the .whl file is in the directory you are running pip from. 如果无法从pypi安装sklearn,则需要确保.whl文件位于运行pip的目录中。

This can be a common occurance on Windows, I for instance have to do the same thing with MySQLClient. 这在Windows上很常见,例如,我必须对MySQLClient做同样的事情。

Just drop the .whl file into your directory and run the following from within an activated venv: 只需将.whl文件拖放到目录中,然后在激活的venv中运行以下命令:

py -m pip install -r requirements.txt

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

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