Questions tagged [virtualenv]

virtualenv is a tool that creates sandboxed Python environments.

virtualenv allows you to create a sandboxed and isolated environment where Python packages can be installed without interfering with other packages on the same machine. With several virtualenvs, many different pieces of Python software with different and even mutually exclusive dependencies can live together.

The source code of this tool is hosted on GitHub.

Basic usage:

$ virtualenv ENV
$ source ENV/bin/activate
(ENV) $ easy_install (package)
(ENV) $ deactivate
$ ...

See the Command reference for a complete list of all available commands.

7398 questions
145
votes
38 answers

pip installing in global site-packages instead of virtualenv

Using pip3 to install a package in a virtualenv causes the package to be installed in the global site-packages folder instead of the one in the virtualenv folder. Here's how I set up Python3 and virtualenv on OS X Mavericks (10.9.1): I installed…
DocZerø
  • 8,037
  • 11
  • 38
  • 66
145
votes
1 answer

How to install a specific version of a package with pip?

I have set up a virtual environment on my server as well as in my local dev environment. On the server, the package django_modeltranslation-0.4.0_beta2 works perfectly fine. However, on my local machine, django_modeltranslation-0.5.0-alpha doesn't…
Houman
  • 64,245
  • 87
  • 278
  • 460
141
votes
13 answers

Problems with pip install numpy - RuntimeError: Broken toolchain: cannot link a simple C program

I'm trying to install numpy (and scipy and matplotlib) into a virturalenv. I keep getting these errors though: RuntimeError: Broken toolchain: cannot link a simple C program ---------------------------------------- Cleaning up... Command python…
Ben
  • 6,986
  • 6
  • 44
  • 71
141
votes
6 answers

Where should virtualenvs be created?

I'm confused as to where I should put my virtualenvs. With my first django project, I created the project with the command django-admin.py startproject djangoproject I then cd'd into the djangoproject directory and ran the command virtualenv…
Jim
  • 13,430
  • 26
  • 104
  • 155
133
votes
6 answers

How to rename a virtualenv in Python?

I misspelled the name of the virtualenv while initializing it using: $ virtualenv vnev I actually intended to create the environment with the name venv. Having tried to rename the vnev folder to venv, I find that this doesn't provide much help. The…
Kshitij Saraogi
  • 6,821
  • 8
  • 41
  • 71
133
votes
17 answers

Vagrant Not Starting Up. User that created VM doesn't match current user

I was trying to start up my vagrant machine, so I navigated to the folder where my vagrantfile is, and used: vagrant up && vagrant ssh but I got the following error message: The VirtualBox VM was created with a user that doesn't match the …
Luke
  • 1,736
  • 2
  • 16
  • 34
130
votes
6 answers

Revert the `--no-site-packages` option with virtualenv

I have created a virtualenv using the --no-site-packages option and installed lots of libraries. Now I would like to revert the --no-site-packages option and use also the global packages. Can I do that without recreating the virtualenv? More…
Olivier Verdier
  • 46,998
  • 29
  • 98
  • 90
130
votes
10 answers

Activate a virtualenv via fabric as deploy user

I want to run my fabric script locally, which will in turn, log into my server, switch user to deploy, activate the projects .virtualenv, which will change dir to the project and issue a git pull. def git_pull(): sudo('su deploy') # here i…
Thomas Schreiber
  • 1,828
  • 2
  • 14
  • 11
129
votes
6 answers

ModuleNotFoundError: No module named 'distutils.core'

I've recently upgraded from Ubuntu 18.04 to 19.04 which has python 3.7. But I work on many projects using Python 3.6. Now when I try to create a virtualenv with Python 36 in PyCharm, it raises: ModuleNotFoundError: No module named…
Milano
  • 18,048
  • 37
  • 153
  • 353
128
votes
10 answers

Activate a virtualenv with a Python script

I want to activate a virtualenv instance from a Python script. I know it's quite easy to do, but all the examples I've seen use it to run commands within the env and then close the subprocess. I simply want to activate the virtualenv and return to…
h3.
  • 10,688
  • 15
  • 51
  • 54
128
votes
12 answers

How to resolve "dyld: Library not loaded: @executable_path.." error

I was trying to check the AWS-CLI version on my MAC OS X. And the below error hit back: dyld: Library not loaded: @executable_path/../.Python Referenced from: /usr/local/aws/bin/python Reason: image not found Abort trap: 6 Any relevant inputs…
Manogna Mujje
  • 1,291
  • 2
  • 7
  • 4
127
votes
8 answers

How do I add a path to PYTHONPATH in virtualenv

I am trying to add a path to the PYTHONPATH environment variable, that would be only visible from a particular virtualenv environment. I tried SET PYTHONPATH=... under a virtualenv command prompt, but that sets the variable for the whole…
Flavien
  • 7,497
  • 10
  • 45
  • 52
126
votes
2 answers

Rename an environment with virtualenvwrapper

I have an environment called doors and I would like to rename it to django for the virtualenvwrapper. I've noticed that if I just rename the folder ~/.virtualenvs/doors to django, I can now call workon django, but the environment still says…
hobbes3
  • 28,078
  • 24
  • 87
  • 116
124
votes
7 answers

Can I install Python windows packages into virtualenvs?

Virtualenv is great: it lets me keep a number of distinct Python installations so that different projects' dependencies aren't all thrown together into a common pile. But if I want to install a package on Windows that's packaged as a .exe installer,…
Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
124
votes
9 answers

How to get virtualenv to work with fish shell?

I'm trying to get virtualenv to work with the fish shell. I have virtualenv installed and it works fine with bash and zsh. However, running the following command returns fish: Unknown command 'source': $ source ~/path/to/bin/activate Does anyone…
drbunsen
  • 10,139
  • 21
  • 66
  • 94