Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with activating virtualenv

I installed python environment by means of commands:

SYS_INSTALL="apt-get install -y"
PIP_INSTALL="pip install"

# Be sure to install setuptools before pip to properly replace easy_install.
$SYS_INSTALL git 
$SYS_INSTALL python-dev
$SYS_INSTALL python-setuptools
$SYS_INSTALL python-pip
$PIP_INSTALL virtualenv

also was able to create new virtual environment:

virtualenv .env

However, after running a command like:

. .env/bin/activate

I got

-bash: .env/bin/activate: No such file or directory

After reviewing folder .env/bin I found only one python file. Whole list of files here:

.env/lib:
python2.7

.env/include:
python2.7

.env/bin:
python

What is the issue here?

SOLUTION add --always-copy

virtualenv .env --always-copy

like image 678
SpanishBoy Avatar asked May 10 '16 11:05

SpanishBoy


People also ask

How do I know if virtualenv is activated?

Note: Before installing a package, look for the name of your virtual environment within parentheses just before your command prompt. In the example above, the name of the environment is venv . If the name shows up, then you know that your virtual environment is active, and you can install your external dependencies.

Do I have to activate virtual environment everytime?

Don't forget to activate your Python virtual environmentBefore a virtual environment can be used in a particular shell session, it has to be activated, by way of a script named activate in the virtual environment's Scripts directory.


2 Answers

For me it works when I do these steps:

  • Go to the directory/folder that you want

  • run virtualenv .env

  • then run source .env/bin/activate

like image 126
Alex Avatar answered Oct 19 '22 23:10

Alex


The accepted answer is incomplete! The suggested code left out your error, but didn't comment on it.

The command . .env/bin/activate would indeed do the same as source on the file activate in the folder .env/bin. In fact, apparently the command "source" is an alias for the command ".", and not the other way around. Note that . here has a space after it, and used differently from the . discussed below (which makes files and folders hidden).

What I notice is that you are calling your folder .env, which is not standard practice. Files and folders preceded by . are made "hidden" by Mac OS X. Standard practice is to call a virtual environment directory env or venv, and to call the virtual environment specification file .env.

So, if your spec file is called .env and your virtual environment directory is called env, you can run either

source env/bin/activate or . env/bin/activate.

like image 23
Zach Siegel Avatar answered Oct 20 '22 01:10

Zach Siegel