0

I am writing a code in python that uses numpy, matplotlib etc.

How to make sure that even a remote web server with python installed but no extra modules, can run the code without errors?

I usually work on linux environment. Hence from source code, I can install the libraries in a prefix directory and can keep that along with my code. Then add pythonpath locally in my python code to use the directory.

But, I started to realize it's not correct way as first thing, it can't work on cross platform as the libraries are different, and my code inside the script to extend the pythonpath may not work due to the use of "/" in path. Also, I am not sure if the compiled code can work in different environments of the same Linux Platform.

So I think I need to create a directory like unix,windows,osx etc. and put my code there? I believe this is what I find when I download any code online. Is that what developers generally do to avoid these issues?

1 Answer 1

2

A popular convention is to list requirements in a text file (requirements.txt) and install them when deploying the project. Depending on your deployment configuration, libraries can be installed in a virtual environment (google keyword: virtualenv), or in a local user folder (pip install --user -r requirements.txt, if this is the only project under this account) or globally (pip install -r requirements.txt, e.g. in a docker container)

Sign up to request clarification or add additional context in comments.

4 Comments

Okay so this is performed by the web administrator right, once we share the code to them? But they need to have pip installed first
And so keeping the complex modules like numpy along with the code is not a popular practice and also not possible or convienient?
first question: it is done by the person deploying the project; CM engineer, devops, CI scripts, web administrator or even developer himself. Second question: yes, it is definitely a bad practice to distribute a copy of numpy with the project code. It is platform dependent, so it is not guaranteed to run properly on a machine with a different CPU architecture or even running a different version of Python
Thank you..that's what I wanted to know :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.