pipenv
pipenv copied to clipboard
Using ``pipenv run /path/to/main.py'' out of the directory of the project.
Hi,
Say, I've a project created by pipenv which named as my-pipenv-project and I use main.py which is located under the directory of my-pipenv-project.
Now, I want to run the main.py with the ``pipenv run'' method without enter the my-pipenv-project directory. What's the correct method for this case?
Regards
This would be useful for using Pipenv projects in Bash scripts.
The correct syntax is pipenv run python -m <package-name>
to run__main__.py
of package. This is the standard naming convention for Python. See python
command-line documentation for more details.
@kalebmckale I think this one is pointing out that whenever you run a pipenv
command it changes directories to the project root which can change the pathing requirements of the script. I never have had time to get back around to thinking about this one.
I'm reading this differently. I read it as I want to run my package as a module without being inside the project directory. Either way, my answer could be wrong as I'm no longer certain if I've done this before. Also, I have a .env
file that adds the project's path to PYTHONPATH
, which might be another reason this works for me.
Either way I am going to close it as stale and if its still a problem requiring support a new issue can be opened.
Actually, ignore my comments. It's too late and my brain is tired. I don't think I know a way to run pipenv run
without being in the project directory that contains the Pipfile
.
In the light of day 🌞 and with a rested 🧠, what you ask is not possible right now and unless I'm mistaken would be quite difficult to implement. Right now, the location of the Pipfile / the directory in which you run pipenv
is used to determine a hash used in the name of the related virtual environment directory. Running pipenv
right now is tied to an existing Pipfile and/or environment or will create one or both. Outside of the directory of your Pipfile, pipenv
has no way to know which Pipfile (assuming you have others) or which virtual environment you're referring to and adding this behavior would likely conflict with its current functionality.