PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, September 21, 2022

[FIXED] How to setup PyCharm to use virtualenv in Vagrant/VirtualBox remote interpreter configuration?

 September 21, 2022     pycharm, ubuntu, vagrant, virtualbox, virtualhost     No comments   

Issue

PyCharm running under Windows.

Ubuntu 14.04 LTS VM hosted under VirtualBox.

Setting up PyCharm to use Vagrant to launch said VM and use the remote Python interpreter works as advertised. However, this also happens to be the interpreter and packages used by Ubuntu.

How would one modify this setup to use one or more virtualenvs on the VM? The idea being that each project could very well have radically different requirements and they should be isolated from each other and the system through virtualenv.

Would this require using Apache VirtualHost to setup separate projects? Any docs on doing that for Python and/or Python/Django projects?


Solution

We are using vagrant and we have more than 100 sites with different virtual environments. I set up the projects within /vagrant/projects folder which is a shared folder between the host and guest. This way we can work on the projects from within vagrant guest machine or from an ide within the host machine depending on the preference of the developer.

Every project has its own apache virtualhost conf and the virtual environments are located in /usr/local/virtualenvs/. For example:

/vagrant/projects/site1 with virtual environment /usr/local/virtualenvs/site1 and so on.

The apache conf for one site looks like this:

<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>

You can also use vagrant-hostmanager plugin to automatically edit the hosts file withing your host and guest machines. So you can directly access your domains without having to edit the hosts files manually all the time.



Answered By - gurel_kaynak
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing