如何设置PyCharm在Vagrant / VirtualBox远程解释器配置中使用virtualenv?

时间:2014-11-07 00:16:09

标签: ubuntu vagrant virtualbox virtualhost pycharm

在Windows下运行PyCharm。

在VirtualBox下托管的Ubuntu 14.04 LTS VM。

设置PyCharm以使用Vagrant启动所述VM并使用远程Python解释器按宣传方式工作。但是,这也恰好是Ubuntu使用的解释器和包。

如何修改此设置以在VM上使用一个或多个virtualenv?我们的想法是每个项目都可以有完全不同的要求,并且应该通过virtualenv将它们彼此隔离开来。

这是否需要使用Apache VirtualHost来设置单独的项目?有关Python和/或Python / Django项目的任何文档吗?

2 个答案:

答案 0 :(得分:4)

我发现接受的答案很有帮助,但符合@ miR的评论......

要将PyCharm设置为使用虚拟环境,您可以编辑/设置virtualenv二进制文件的Python解释器路径。 例如。我的virtualenv(通过ssh在Ubuntu Vagrant VM中创建)是/home/vagrant/virtualenvs/project/bin/python3所以我只是将那条路径复制到" Python解释器路径" "项目口译员"。

这很好用。我甚至可以使用PyCharm接口将软件包安装到Vagrant VM上的virtualenv中。

答案 1 :(得分:-1)

我们正在使用vagrant,我们有超过100个具有不同虚拟环境的站点。我在/ vagrant / projects文件夹中设置项目,该文件夹是主机和来宾之间的共享文件夹。通过这种方式,我们可以根据开发人员的偏好从流浪客户机或主机内的ide处理项目。

每个项目都有自己的apache virtualhost conf,虚拟环境位于/ usr / local / virtualenvs /中。例如:

/ vagrant / projects / site1与虚拟环境/ usr / local / virtualenvs / site1等等。

一个站点的apache conf看起来像这样:

<VirtualHost *:80>
   ServerAdmin your@email.com
   ServerName site1

   ErrorLog /var/log/apache2/error_site1.log
   CustomLog /var/log/apache2/access_site1.log common

   WSGIDaemonProcess site1 user=www-data group=www-data umask=0002 threads=3 python-path=/vagrant/projects/site1/web/site1:/usr/local/virtualenvs/site1/lib/python2.7/site-packages/
   WSGIProcessGroup site1
   WSGIScriptAlias / /vagrant/projects/site1/web/server.wsgi
   <Directory />
       Options Indexes FollowSymLinks none ExecCGI
       AllowOverride None
       Order allow,deny
       Allow from all
       ServerSignature Off
   </Directory>
</VirtualHost>

您还可以使用vagrant-hostmanager插件自动编辑主机和来宾计算机的hosts文件。因此,您可以直接访问您的域,而无需一直手动编辑主机文件。

相关问题