So I've written a bunch of Python3 scripts that I want to run on a shared work computer. This computer has python2.7 installed on it, and many scheduled 2.7 scripts, and I have to make sure those continue untouched. So I thought a kind of portable or virtual python3 environment I could keep just for my scripts.
If there was a tweak to the things I tried or a new way I didn't consider, that'd be much appreciated. Also sorry for long post, wanted to be specific.
What I've tried:
1) Installing a portable version of python3 (WinPython 3.7).
Then in the .bat file to run my script I put:
SET PYTHONPATH = "C:\Localdata\...\WPy-3702\python-3.7.0.amd64\Lib\site-packages"
"C:\Localdata\...\WPy-3702\python-3.7.0.amd64\python.exe" test.py
Where test.py is simply:
import six
print(six.__file__)
Now this works fine on my own laptop, returning the winpython site-package directory:
> C:\Localdata\...\WPy-3702\python-3.7.0.amd64\Lib\site-packages\six.py
However, with all the above being equal, the shared computer reverts to the installed 2.7 library.
> C:\Program Files (x86)\Python27\lib\site-packages\six.py
This breaks it of course and seems the root of my issue. I've checked and there is a six.py in the winpython site-packages folder. I've tried different versions/installations of winpython with no luck. (Ideally if someone pointed out a simple command here I am missing that could fix this, that would be great.)
FYI if I run python from the "WinPython Command Prompt.exe" that comes bundled, it is indeed version 3.7, just it won't use the local 3.7 site-package libraries...
2) Installing Anaconda3 and not adding to PATH.
The installation completes, but I'm left with only the Anaconda Prompt in the start menu (no jupyter, spyder etc.) and Anaconda Prompt errors out as soon as I try open it:
> 'C:\Users\...\anaconda3\Scripts\activate.bat' is not recognized as an
internal or external command, operable program or batch file.
I've experience with this issue on other work PCs and the solution is to remove the default python and reinstall Anaconda, but as I said before I can't touch the current Py2 installation without annoying a LOT of people, so another dead-end.
(Although the installation is somehow botched, the anaconda3 files are still installed, so I tried the same test.py+batchfile trick to the anaconda3 site packages but it does the same deal).
3) Creating a Venv:
Ok I admit I'm a bit naive here, if I read this though: Why virtualenv relies on the global python instead of the local one, after being pulled? it looks like I will have the same issues as above.
From my previous post How to run a python script locally in a virtual environment on someone elses windows machine and have it consistently work? the answer to use pyinstaller is useful for a once off, but I've a lot of scripts I now want to run on the same computer, so a 500MB+ package per script would be too cumbersome.
When using the set command. Any spaces you use before the equals symbol is part of the variable name itself. So if you want to use that variable you then have to reference it as %myvar %
with a space at the end.
It is also not a best practice to assign quotes to a variable. You can use them though to protect special characters in the value of the variable and it also helps avoid trailing spaces at the end of the value of the variable.
SET "PYTHONPATH=C:\Localdata\...\WPy-3702\python-3.7.0.amd64\Lib\site-packages"