Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use virtualenvwrapper from within a Python script
    primarykey
    data
    text
    <p>I have succesfully installed <code>virtualenv</code> and <code>virtualenvwrapper</code> on my system. It is working perfectly. For future convenience I want to create a script which installs all my favourite modules into an environment I name <code>pynumeric</code>, to be located in <code>~/.virtualenvs</code>. For this script I need to use <code>virtualenvwrapper</code> from wihtin my script. This, is unfortunately not working for me somehow. I keep on getting errors that <code>workon</code> and <code>mkvirtualenv</code> do not exist.</p> <p>So basically my question boils down to: Why does <code>virtualenvwrapper</code> work in a terminal and <strong>not</strong> from within my Python script?</p> <p><strong>install_pynumeric.py (EDIT)</strong></p> <pre><code>#!/usr/bin/python import os import sys import subprocess as sp # Set CPU frequency governer to performance #sp.check_call('cpuset gov performance', shell=True) # Check for parent directory of virtual environments if not os.path.isdir('/home/carlos/.virtualenvs'): sys.exit('The parent directory for virtual environments does not exist yet. Create it before preceeding.') # Create virtual environment pynumeric if it does not exist yet and activate if not os.path.isdir('/home/carlos/.virtualenvs/pynumeric'): sp.check_call('mkvirtualenv pynumeric', shell=True) # Activate pynumeric sp.check_call('workon pynumeric', shell=True) # List of Python modules to be installed modules = ['numpy', 'scipy', 'sympy', 'matplotlib', 'pyqt4', 'sphinx', 'rope', 'pyflakes', 'ipython', 'pylint', 'psutil', 'spyder', 'pydstool' ] # Install modules for m in modules: cmd = 'pip install ' + m sp.check_call(cmd, shell=True) # Deactivate pynumeric sp.check_call('deactivate', shell=True) # Set CPU frequency governer to ondemand #sp.check_call('cpuset gov ondemand', shell=True) </code></pre> <p>I get the following error now:</p> <pre><code>/bin/sh: mkvirtualenv: command not found Traceback (most recent call last): File "./install_pynumeric.py", line 16, in &lt;module&gt; sp.check_call('mkvirtualenv pynumeric', shell=True) File "/usr/lib/python2.7/subprocess.py", line 542, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command 'mkvirtualenv pynumeric' returned non-zero exit status 127 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload