3

Pipenv virtual environnements (venv) will be shared with children folders. So for example if you have installed an venv in ~/foo/, it will be accessible in ~/foo/baz/

But what if you want to share the same venv between ~/foo/bob/ and ~/baz/alice/ ?

The following kind of worked for me. I hope it can help.

asked Feb 13, 2018 at 18:06

2 Answers 2

3

There's a undocumented feature in pipenv: if you create a file named .venv in the project root with a path to a virtualenv, pipenv will use that instead of an autogenerated path.

(You'll still need to keep Pipfile's and Pipfile.locks synchronized. Making them symlinks as @MalikKoné suggests may do, but not if Pipfiles are under version control as they are supposed to.)

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.

answered Jul 6, 2019 at 2:19
Sign up to request clarification or add additional context in comments.

Comments

1

To share virutal env with pipenv Create a directory ~/foo/bob/

mkdir -p ~/foo/bob/ ; cd ~/foo/bob/ 

create a virtual env in ~/foo/bob/

pipenv --three

This will create ~/.local/share/virtualenvs/bob-signature/

Install whatever packages you need. For example

pipenv install jupyter

This will create a Pipfile.lock in ~/foo/bob/

Create another directory, say ~/baz/alice/ and create a venv there

mkdir -p ~/baz/alice ; cd ~/baz/alice/ ; pipenv --three 

As before pipenv will have created alice-signature/ in ~/.local/share/virtualenvs/. Remove that folder and replace it by a link to bob-signature

cd ~/.local/share/virtualenvs/
rm -r alice-signature/
ln -s bob-signature/ alice-signature

In ~/baz/alice/, link Pipfile and Pipfile.lock to the ones in ~/baz/bob/

cd ~/baz/alice/ ;
rm Pipfile ; rm Pipfile.lock
ln -s ~/foo/bob/Pipfile . ; ln -s ~/foo/bob/Pipfile.lock . 

Now, You should have a venv accessible from alice/ or bob/, and packages installed from any of those directories will be shared.

answered Feb 13, 2018 at 18:06

1 Comment

Symlinking won't do if Pipfiles are under version control (as they are supposed to).

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.