Paal Pedersen
Paal Pedersen

Reputation: 1287

Best Practice installing none-polluting pip packages without using virtual environments

This might be a redundant question. But what i like to is to install a pip packages in a sys.path which I am the legal owner of.

To make this work I had to do a ugly hack on Windows to find which folders I own from the list of sys.path. It would be great if there was a subset of sys.path which was owned by the user like sys.owned_path, but thats probably not so for a reason I dont know. And I would really like pathlib.Path().owner() to be implemented on windows.

so from the script I want to be able to install required packages if it is missing. Cause the Python Application is running inside another Application. So I would like to always get a path I own on the sys path and do:

app.exe python -m pip install package -t C:\a\clean\folder\in\sys\path\owned\by\the\user 

but this app can also run on Linux With another name, so it has to be cross platform independent:

appengine python -m pip install package -t /a/clean/unix/path/owned/by/the/user

On Windows I had to use subprocess to run a dir commmand to get the owner of a path, which there must be a faster lower level entrance to get this result?

Sorry for the fractured questions.

Upvotes: 2

Views: 163

Answers (1)

AnsFourtyTwo
AnsFourtyTwo

Reputation: 2518

You can install packages to some user specific location using the --user option:

pip install <package-name> --user

Instead of some system location, e.g. on linux /usr/lib/python3.6, pip will install packages to a location specific to a user, e.g. ~/.local/lib/python3.6.

Upvotes: 4

Related Questions