Connor
Connor

Reputation: 4884

How to create a new virtualenv with pipenv in a subdirectory of a virtualenv?

I have this directory structure:

code/
├── some_script.py
├── Pipfile
├── Pipfile.lock
└── subdirectory/
    └── script_to_run.py

Inside subdirectory/ directory, I want to run script_to_run.py, however when I pipenv run python3 script_to_run.py I get the problem that pipenv assumes I'm in the code/ directory, rather than the subdirectory/ directory.

How do I generate a new virtualenv for subdirectory/ with pipenv?

Upvotes: 3

Views: 3940

Answers (3)

S7bvwqX
S7bvwqX

Reputation: 197

For newbies like me:

Create an empty file (fill with 1 space if using nano) named "Pipfile" (must with capital "P").

Then just run "pipenv shell" in the subfolder. It should create a new env in the subfolder.

Upvotes: 1

Connor
Connor

Reputation: 4884

cd subdirectory
touch Pipfile
pipenv run python3 script_to_run.py

This will generate a new virtualenv for this subdirectory.

Upvotes: 5

Merig
Merig

Reputation: 2011

You can simply call pipenv run subdirectory/script_to_run.py

Upvotes: 0

Related Questions