cstoltze
cstoltze

Reputation: 916

Executing pipfile scripts

How can I execute the scripts defined in the Pipfile?

Following the syntax found here, I defined the scripts section in my pipfile as follows:

[scripts]
tests = "bash ./run-tests.sh"

After running $ pipenv install, how can I call the tests script?

I've tried the following without success:

$ tests

$ pipenv tests

$ pipenv run tests

$ pipenv shell (virtual env) $ tests

Upvotes: 14

Views: 24083

Answers (5)

Charles Y.
Charles Y.

Reputation: 395

It would be helpful to know what you are getting with each of your attempts to help troubleshoot what might be wrong.

https://pipenv.pypa.io/en/latest/advanced/#custom-script-shortcuts gives a brief introduction to scripts and indicates that your attempt of pipenv run tests is the right way to use the script from your Pipfile.

Upvotes: 0

Iuri Guilherme
Iuri Guilherme

Reputation: 461

The canonical answer to this would be simply:

pipenv run tests

Your Pipfile's syntax is correct and this is the only way to run scripts.

If pipenv run tests don't work, something else is wrong with your setup.

Make sure you at some point have ever run pipenv install, you can safely run that again to be sure, or pipenv update if you need to lock and sync again.

Also make sure that when you type pipenv in your shell you're using the proper pipenv. Some Python setups end up forcing you to call it like one of those following ways:

$ pipenv
$ python3 -m pipenv
$ pyenv exec python -m pipenv
$ ~/.local/bin/pipenv

That happens because most users may and probably have more than one python interpreter, more than one pip, more than one pipenv, and so on, in such a way that you may never know which site-packages and virtualenvs simply typing pipenv will give you.

For example, if you issue these commands on Linux:

$ pip install --user pipenv
$ sudo pip install pipenv
$ python3 -m pip install --user --upgrade pip pipenv
$ pip3 install pipenv

You will have at least two pipenv installations in your system and which one is called when you type in pipenv will depend on how your operational system handled those commands and which post installation triggers were performed.

Upvotes: 1

Deca
Deca

Reputation: 9

To install packages exactly as specified in Pipfile.lock, you should run:

pipenv sync

After that, to keep working in the pipenv, you should run:

pipenv shell

(Source: https://pipenv-fork.readthedocs.io/en/latest/advanced.html)

Upvotes: 0

Rémi Bourgeon
Rémi Bourgeon

Reputation: 164

I had the same problem and I happened to solve it thanks to a discussion in this issue.

Long story short, I only updated pipenv globally before beginning my project, not locally. So I still was using the old version.

To properly update the version of pipenv that you are using, you have to upgrade pipenv also for the user you are using for the project. Hence :

$ sudo pip install pipenv --upgrade --user

solved my problem.

May this silly mistake be my first SO contribution, and my eternal shame.

Edit:

As noted by Coleman Stoltze, the correct way to call the script is :

$ pipenv run tests

Upvotes: 14

pei
pei

Reputation: 11

Try this:

$ pipenv shell 

$ pipenv run tests

Upvotes: 1

Related Questions