gregneagle / relocatable-python

A tool for building standalone relocatable Python.framework bundles
Apache License 2.0
156 stars 42 forks source link

Prevent pip search for dependencies in other paths #2

Closed LcTrKiD closed 4 years ago

LcTrKiD commented 4 years ago

Behavior: Users having python3 from Brew could have used pip to install libraries in the '/Users/user/Library/Python/3.7/...'. If you have previously installed a library in the mentioned folder the "new" pip will see that library as installed and it won't be available in your "relocated python".

How to reproduce it: If you want to reproduce this behavior you should install python with brew (do it only for testing purpose...) and use pip3 to install 'xattr' then use relocatable-python and you won't get 'xattr' in your newly created framework.

gregneagle commented 4 years ago

-s looks like the right approach.

erikng commented 4 years ago

So I thought this was interesting and rebuilt my python framework and noticed something interesting that I don't fully understand the ramifications on.

for xattr the only thing that changed was the shebang (because I've since moved the source project somewhere else

Python.framework/Versions/3.7/bin/xattr

#!/somewhere/Python.framework/Versions/3.7/bin/python3.7
#!/now_somewhere_else/Python.framework/Versions/3.7/bin/python3.7
gregneagle commented 4 years ago

None of the executable scripts inside the framework (scripts that have a shebang line) are relocatable. Shebang lines must be absolute paths.

The framework is relocatable: you can run the Python interpreter within and/or link to the libraries no matter where the framework is in the filesystem.

Any scripts with shebang lines inside the framework are not relocatable. Most of them will have a shebang line of #!/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 some will have a shebang line of #!/<wherever you built the framework>/Python.framework/Versions/3.7/bin/python3.7

The purpose of this relocatable framework is not to be a general-purpose install of Python tools. It is to be a relocatable Python interpreter.

If you need the scripts inside Python.framework/Versions/3.7/bin to be directly executable, you'll need to 1) Decide on a final absolute installation location for the framework, and 2) edit them all to point the shebang to the final absolute installation location for the framework + /Versions/3.7/bin/python3.7 (or python3.7m)