简体   繁体   English

在虚拟环境python中安装站点包

[英]Install site-packages inside virtual environment python

I am working on deploying my django application using uwsgi and nginx on a RHEL with pre installed python packages. 我正在使用uwsgi和nginx在具有预安装的python软件包的RHEL上部署django应用程序。 Server is installed with uwsgi and nginx globally(as root). 服务器在全局(以root用户身份)中安装了uwsgi和nginx。 My server is not connected to internet. 我的服务器未连接到互联网。

I have secure copied my django project inside this server. 我已经在该服务器中安全地复制了我的django项目。 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

All is cool. 一切都很酷。 It creates a virtual environment with python 3.5. 它使用python 3.5创建一个虚拟环境。

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 示例django,redis等。当我对--system-site-packages执行上述命令时,会引发此错误

PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.6/site-packages/wheel-0.29.0.dist-info' PermissionError:[Errno 13]权限被拒绝:'/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 `? 有没有更干净的方法可以做到这一点,或者它在哪里出错?

这可能是由于您的计算机中存在另一个用户而引起的。只需检查您是否具有系统特权,否则请编辑文件的属性并授予其权限。

You may try: 您可以尝试:

$ pip freeze

where pip is the system-wide pip . 其中pip是系统范围的pip If it outputs anything, then just do: 如果输出任何内容,则只需执行以下操作:

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

In this way you will tell the virtual environment's pip to install all the python packages that are installed system-wide. 这样,您将告诉虚拟环境的pip安装在系统范围内安装的所有python软件包。

If pip freeze doesn't work, this is a privilleges issue, you have to elaborate this as/with an admin. 如果pip freeze不起作用,这是一个难题,您必须以管理员身份详细说明。

UPD: You may need to install additional packages as python3-dev, build-essential etc for pip install -r requirements.txt to work. UPD:您可能需要安装其他软件包,例如python3-dev,build-essential等,才能使pip install -r requirements.txt正常工作。

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

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