在虚拟环境 python 中安装站点包 [英] Install site-packages inside virtual environment python

查看:109
本文介绍了在虚拟环境 python 中安装站点包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 uwsgi 和 nginx 在 RHEL 上部署我的 django 应用程序,并预先安装了 python 包.服务器与 uwsgi 和 nginx 一起全局安装(以 root 身份).我的服务器没有连接到互联网.

I am working on deploying my django application using uwsgi and nginx on a RHEL with pre installed python packages. Server is installed with uwsgi and nginx globally(as root). My server is not connected to internet.

我已在此服务器中安全地复制了我的 django 项目.对于最佳实践,我被告知使用虚拟环境,当我执行命令时,

I have secure copied my django project inside this server. For best practices I am told to use virtual environment and when I do the command,

virtualenv -p /usr/local/lib/python3.5/bin/python3.5 venv

一切都很酷.它使用 python 3.5 创建了一个虚拟环境.

All is cool. It creates a virtual environment with python 3.5.

但问题是,我需要这些预先安装在服务器上的站点包到这个虚拟环境中.示例 django、redis 等.当我使用 --system-site-packages 执行上述命令时,它会抛出此错误

But the problem is, I need these site packages which is pre installed on the server into this virtual environment. Example django, redis etc. When I do the above command with --system-site-packages it throws me this error

权限错误:[Errno 13] 权限被拒绝:'/usr/local/lib/python3.6/site-packages/wheel-0.29.0.dist-info'

PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.6/site-packages/wheel-0.29.0.dist-info'

有没有更简洁的方法来做到这一点,或者哪里出了问题`?

Is there a cleaner way to do this or where is it going wrong `?

推荐答案

你可以试试:

$ pip freeze

其中 pip 是系统范围的 pip.如果它输出任何东西,那么就这样做:

where pip is the system-wide pip. If it outputs anything, then just do:

$ pip freeze > requirements.txt;
$ source /path/to/venv/bin/activate && pip install -r requirements.txt;

通过这种方式,您将告诉虚拟环境的 pip 安装系统范围内安装的所有 python 包.

In this way you will tell the virtual environment's pip to install all the python packages that are installed system-wide.

如果 pip freeze 不起作用,这是一个特权问题,您必须作为/与管理员详细说明.

If pip freeze doesn't work, this is a privilleges issue, you have to elaborate this as/with an admin.

UPD:您可能需要安装额外的软件包,如 python3-dev、build-essential 等,pip install -r requirements.txt 才能工作.

UPD: You may need to install additional packages as python3-dev, build-essential etc for pip install -r requirements.txt to work.

这篇关于在虚拟环境 python 中安装站点包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆