2

Pipenv allows the use of the system Python instead of creating a virtualenv to install packages:

$ pipenv install --system

But if I do so, subsequent pipenv runs are trying to create the virtualenv instead of using the system Python. In particular, I'm interested in using Pipenv scripts:

$ pipenv run postinstall
Creating a virtualenv for this project...

Is there a way to use the system Python interpreter for Pipenv scripts?

2 Answers 2

2

As far as I'm aware, it's not possible do run the scripts inside the Pipfile with pipenv if you don't use any

The maintainers of pipenv decided against such a feature a couple years ago (e.g. see the discussion at Add a --system flag to pipenv run #2693), and I can't find anything newer that would say otherwise.

If you want to run a script in your system installation, just run it normally in the terminal. If you work without a virtual environment, you don't need pipenv to run any scripts. E.g. if you have defined app = "uvicorn my_app.main:app --port 8080" in the script section and make a system installation, you can afterwards just call uvicorn my_app.main:app --port 8080 in the terminal.

I understand that there is some convenience to define some scripts/aliases in the Pipfile. But if you need those also outside virtual environments, it would be better to just create actual shell scripts. And if you want to have the pipenv run functionality to keep working, just make sure that these scripts defined in the Pipfile call the shell scripts in order to avoid code duplication.

Sign up to request clarification or add additional context in comments.

Comments

-1

When setting up your pipenv you can specify the version of Python by using: pipenv --python 3.6, to use Python3.6.

Editing the Pipfile also works, by changing:

[requires]
python_version = "3.6.6"

to the specific version of Python you want.

If you did all of this and are still having trouble with accessing the correct version of Python from within pipenv shell then you might want to check your .bashrc file to be sure that you don't have an alias for a specific version of Python.

1 Comment

I'm aware I can specify the Python version and I'm not trying to use pipenv shell.

Your Answer

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.