When running mssql-cli from within an activated virtualenv, everything is fine because the virtual env's python is the first match on the PATH. However, when invoking mssql-cli from myvenv/bin/mssql-cli while the virtual environment is not activated, we get
> myvenv/bin/mssql-cli
/usr/bin/python: Error while finding module specification for 'mssqlcli.main' (ModuleNotFoundError: No module named 'mssqlcli')
as noted in pypa/pipx#12.
This is because the script mssql-cli is custom made and hardcoded to invoke a new bash shell, ignoring any virtual environment.
There are a few solutions. The first is easiest and most common.
- Use the standard
entry_points entry instead of scripts
entry_points = {"console_scripts": [
"mssql-cli.bat = mssqlcli.main:main",
"mssql-cli = mssqlcli.main:main"
]},
- Leave as a script, but use python instead of bash; make the interpreter
/usr/bin/env python instead of bash, similar to how awscli does it: https://github.com/aws/aws-cli/blob/develop/bin/aws
- In the script
mssql-cli test if there is an activate script present, and if so, run source activate before running python -m mssqlcli.main "$@". This is hacky and I would not go this route.
When running
mssql-clifrom within an activated virtualenv, everything is fine because the virtual env'spythonis the first match on the PATH. However, when invokingmssql-clifrommyvenv/bin/mssql-cliwhile the virtual environment is not activated, we getas noted in pypa/pipx#12.
This is because the script
mssql-cliis custom made and hardcoded to invoke a new bash shell, ignoring any virtual environment.There are a few solutions. The first is easiest and most common.
entry_pointsentry instead ofscripts/usr/bin/env pythoninstead ofbash, similar to how awscli does it: https://github.com/aws/aws-cli/blob/develop/bin/awsmssql-clitest if there is anactivatescript present, and if so, runsource activatebefore runningpython -m mssqlcli.main "$@". This is hacky and I would not go this route.