0

I have the following problem: I have to run some test/diagnostic Python script on a Windows system. Due to explicit requirement, the system has no default system-wide Python instance, but there are two different Python instances installed, used locally by applications running on the system. However, both these instances lack some basic modules my script uses (like logging, urllib, configparser etc.).

I want to run %PYTHONPATH%\python.exe myscript.py where %PYTHONPATH% points to one of the installed Python instances, but install the required additional modules "somewhere" outside %PYTHONPATH% (preferrably, in the same directory where my script is installed) so that my script can use them.

As my script is a test tool, it should not modify the OS or installed software, so the Python installation under %PYTHONPATH% should not be changed in any way.

It is also expected that the installation can be fully automated, ie. the best way to install would be just have the modules in the same .zip file with my script which is unpacked onto the target path.

It is also important that the system has no Internet access, so I have to download required files on another machine and copy them to the target system.

Can you guide me how to do it?

2 Answers 2

1

I found an answer myself - it is quite simple:

  1. obtain the zip file containing standard modules from the appropriate Python version distribution (in my case it was the file python38.zip, it is inside the main zip file downloadable from Python site)
  2. Unpack the contents of this file to c:\mydir\Python38\site-packages, where c:\mydir is the directory containing my script
  3. set the environment variable PYTHONUSERBASE=c:\mydir before running my script

Now I can run the script and it finds all "missing" standard modules in c:\mydir\Python38\site-packages.

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

Comments

0

I think what youy are seeking for is a python virtual environment. ( internet needed )

Check : https://docs.python.org/fr/3/library/venv.html

Then for the installation, you can creat a .exe file containing all dependencies. (no internet needed)

Check: https://www.pyinstaller.org/

3 Comments

I don't want to install another, third Python instance onto the machine. I just want to add the missing modules while using the already installed Python. I found a simple method to do it - check my own answer.
and why can't you just make an .exe of the python project to deploy it on other machines ?
These scripts have been used for years, while default instance of Python was present on target systems. It is just a recent change that they got rid of default Python and each app installs their own. I don't want to make big changes to the scripts especially that once installed they auto-update themselves from a central server by just overwriting the main .py file. Also backwards compatibility needs to be provided. I found a solution that does what I need so there's no need to redesign everything.

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.