Reputation: 5101
Actually, pipenv will install the virtualenv with a path like this :
$WORKON_HOME/<base_dir>-<hash>
Is it possible to have exactly the path I want, that is without the base_dir
and the hash
, for exemple :
/home/user/myapp_venv
Upvotes: 18
Views: 13387
Reputation: 36106
There's an undocumented feature in pipenv
: if you create a file named .venv
in the project root with a path in it, pipenv
will use that instead of an autogenerated path.
This, however, is more fit for cases when you already have an established set of environments that you wish to reuse. Otherwise, placing environments in arbitrary places is prone to create a mess eventually. pipenv
relieves you from this task specifically to keep them all in one predictable place and eliminate accidental collisions from human error.
Upvotes: 14
Reputation: 988
Creating a directory .venv in the project then try to initiate with pipenv install <some package>
did not work for me at the first in my mac, it was always creating virtual environment somewhere else. Though later I figure it out the reason. The hack is, first cd
to the project folder cd /Home/.../MyProject
then create a empty Pipfile touch Pipfile
the create a directory mkdir .venv
should work. Now you can run pipenv install
and .venv folder will be used.
Now the elaboration is given form the source code. When the pipenv try to create create a virtual env it looks to the directory dot_venv = os.path.join(self.project_directory, ".venv")
(taken from source code) and thats how the self.project_directory
looks like:
@property
def project_directory(self):
# type: () -> str
return os.path.abspath(os.path.join(self.pipfile_location, os.pardir))
So that function looks for the pipfile location to create the path it will create the virtual environment. So if you create the empty Pipfile
before hand it is confirmed that it will find that file and then find the .venv directory and create the path all together.
Upvotes: -1
Reputation: 129
In windows, Pycharm user by
make .venv fold in project
Settings->Project->Project interpreter->pipenv Environment
it works for me
Upvotes: 1
Reputation: 773
Apart from using a custom location, you can also install the virtualenv in your project's directory. Just add the following line in your .bashrc/.zshrc file:
export PIPENV_VENV_IN_PROJECT=1
Just wanted to let others know that there is another approach available too.
Should you keep the virtualenv inside or outside the project's directory is an opinionated question afterall.
Upvotes: 29
Reputation: 16654
There is an undocumented feature of pipenv, it could locate virtualenv path from VIRTUAL_ENV
environment variable, but you need to create virtualenv manually:
virtualenv /home/user/myapp_venv
VIRTUAL_ENV=/home/user/myapp_venv pipenv install
Upvotes: 19