Setting up Python virtualenv: Difference between revisions

From HPCwiki
Jump to navigation Jump to search
No edit summary
Phase 1 § 5 P1.5.5: content merged into Python (built-in venv supersedes virtualenv/pyvenv) (via update-page on MediaWiki MCP Server)
Tag: New redirect
 
(32 intermediate revisions by 6 users not shown)
Line 1: Line 1:
== creating a new virtual environment ==
#REDIRECT [[Python#Virtual environments]]
 
<source lang='bash'>
virtualenv newenv
</source>
 
== activating a virtual environment ==
<source lang='bash'>
source newenv/bin/activate
</source>
<code>
  (newenv)hjm@ubuntu:~$
</code>
== installing modules on the virtual environment ==
Installing modules is the same as usual. The difference is that modules are in <code>/path/to/virtenv/lib</code>, which may be living somewhere on your home directory. When working from the virtual environment, the default <code>easy_install</code> will belong to the python version that is currently active. This means that the executable in <code>/path/to/virtenv/bin</code> are in fact the first in the <code>$PATH</code>.
<source lang='bash'>
easy_install numpy
</source>
<source lang='bash'>
python setup.py install
</source>
 
== deactivating a virtual environment ==
<source lang='bash'>
deactivate
</source>
=== Make IPython work under virtualenv === 
source testenv/bin/activate
 
<code>
    File "/usr/bin/ipython", line 11
    print "Could not start qtconsole. Please install ipython-qtconsole"
                                                                      ^
</code>
This can be resolved by adding a soft link with the name <code>ipython</code> to the <code>bin</code> directory in the virtual environment folder.
<source lang='bash'>
ln -s /path/to/virtenv/bin/ipython3 /path/to/virtenv/bin/ipython
</source>

Latest revision as of 14:01, 16 June 2026