I\'ve been making a python project using pipenv, and I want to be able to run it in a terminal from any location on my (linux) system. Specifically, say I have the following
You should use the standard setuptools library to write a setup.py file. In particular you can write an entry_points section that names your main script:
entry_points={
'console_scripts': [
'alias_to_my_project = project.main.main'
]
}
Once you've done this, you can activate and install your package into your virtual environment
pipenv install -e .
# or without pipenv
. ~/vpy/bin/activate
pip install -e .
This will create a wrapper script in $VIRTUAL_ENV/bin/alias_to_my_project
that loads the project.main
Python module and calls its main
function.
The wrapper script knows about the virtual environment and can be called directly without specifically activating the virtual environment. So you can do something like
ln -s $VIRTUAL_ENV/bin/alias_to_my_project $HOME/bin/alias_to_my_project
PATH=$HOME/bin:$PATH
and it will always be available.