Slowly's truly portable Python Environment Creation Notes

Last updated 02-24-2017
Python 2 URL https://www.python.org/downloads/release/python-2713
Python 3 URL https://www.python.org/downloads/release/python-360
Python Major/Minor Upgrades

How to upgrade python from x.x.n to x.x.n+1 ?

Hi,

I want to upgrade my python version from 2.4.3 to 2.4.4 in place, cuz I have a lot of installed python packages...is this possible?

Thanks.

xiaojf

ONLY if it is a tertiary version (3rd digit or lower). If you are upgrading to a major new version of python, or a minor version (2nd digit), it will NOT work. You must install the new major/minor version, then reinstall all your packages. Since you're only upgrading to a new tertiary version, you'll be OK.

ALSO...for version 2, the installer puts the runtime DLL in the *WINDOWS SYSTEM FOLDER*, so you will have to make sure that that DLL is moved to the installation directory, if you want portability.

The python 3 installer does not do this and puts its runtime DLL into the installation directory.

--

Tim Roberts

Providenza & Boekelheide, Inc.

Pip To GET pip, if the python installation doesn't have it:
get-pip.py
To upgrade pip itself:
python -m pip install --upgrade pip
PythonWin URL https://sourceforge.net/projects/pywin32/files/pywin32/Build 220   Installing pywin32 from pip is much easier than that stupid instaaaalllll (and doesn't require admin rights):
pip install numpy pypiwin32
If that gives the " Fatal error in launcher: Unable to create process using " error, then use:
python[2 | 3] -m pip install <packagename> (...)

...for PythonWin and the python extensions, pypiwin32 is the package name you want to use for both 32-bit and 64-bit installations.

To get the extensions to import without error into other python environments where they are not installed, even if you do not have admin rights:

  1. Ensure that the extensions are working where they are installed.
  2. copy the following DLLs to the SAME directory where the PYTHON.EXE is located:
    pythoncom27.dll
    pythoncomloader27.dll
    pywintypes27.dll
  3. Make sure that the python runtime DLL (python[majornumber][minornumber].dll) is also located in the same directory where the python.exe file is located. That will ensure that the environment is truly portable anyway.
  4. Run the following code before you run code that imports modules from both environments:
    import sys
    
    myPaths = [
               'InstallPath\\lib\\site-packages', 
               'InstallPath\\Lib\\site-packages\\pythonwin', 
               'InstallPath\\Lib\\site-packages\\pythonwin\pywin',
               'InstallPath\\lib\\site-packages\\pywin32_system32',
               'InstallPath\\lib\\site-packages\\win32', 
               'InstallPath\\lib\\site-packages\\win32com', 
               'InstallPath\\lib\\site-packages\\win32comext', 
               'InstallPath\\lib\\site-packages\\win32\\lib'
              ]
    for aPath in myPaths:
        sys.path.insert(1, aPath)
                      
Python.NET https://sourceforge.net/projects/pythonnet/files/?source=navbar (old, pre-2013, won't work with modern versions of .NET)
IronPython https://github.com/IronLanguages/main/releases/tag/ipy-2.7.7  (This is the Python.NET you should use)
Extensions

cython, statsmodels, 'numpy-mkl'*, scipy, scandir, pysal2, matplotlib, pandas, nose, ggplot, pygal, sympy, bokeh, ipython, notebook, seaborn, clusterpy1, xlrd, xlwt, openpyxl, readline/gnureadline (OSX only), pyreadline (windows only), futures, arcrest, TextBlob, simplejson, xnumpy, swag, pytest, coverage, pygame, cherrypy, lxml, twython, py2exe5, pyinstaller, pyopengl, pyglet, sphinx, scapy6, scikit-learn, scikit-plot, Qt.py, sip, sift, opencv-python, pyqt54, wxPython3.

Use help('modules') to get a list of installed and deprecated extensions.

They're all located at the pypi repository, located here or here

*NOTE: DO NOT use the plain numpy package. It MUST be the numpy+mkl package, or several of the packages in this list won't work. I used Gohlke's wheel (below) because I couldn't find the special numpy package in pypi.

1Even though clusterpy is in the python 3 pypi index, the source code has not been updated for python 3. To update it, in the __init__.py file, remove the from core import * line, and update the syntax for all the print statements.

2Even though pysal is in the python 3 pypi index for 32-bit windows, the entry on pypi has not been updated for python 3 for 32-bit windows. Use the .WHL file instead.

3WxPython requires a special pip install string. Get it here.

4PyQt will not install on OSX via PIP. On Windows, it will only install in Python 3. The parameter is case sensitive.

5py2exe is for python 3 only.

6scapy is for python 2 only. You MUST have admin rights on the installation machine because scapy REQUIRES winpcap to be installed. Thus scapy is not portable at this time.

If trying an install on Windows and it doesn't work, download the compiled .WHL file from Christopher Gohlke's Windows Binary Scientific python extensions repository, and install it directly using:

pip install [.whl file name]

...don't rename the file; copy and paste from an explorer window. If trying an install on OSX/*nix and the install doesn't work...you're out of luck, you'll have to figure out how to build it manually.

R environment variables listing

rpy2 There is a report that pandas is deprecated and will be replaced by rpy2. But I just can't get clang to compile it on OSX, even if I copy hundreds of includes into clang's include paths for this wheel. I was able to get rpy2 installed on windows successfully if I use Gohlke's wheel. Same issue with GDAL. The issue is discussed here but the solution is extremely complex given the risk. - 02/07/2017

Portable Python is not being developed anymore. At the moment there are several better and more up-to-date alternatives:

PythonXY

Python(x,y) is a free scientific and engineering development software for numerical computations, data analysis and data visualization based on Python programming language, Qt graphical user interfaces and Spyder interactive scientific development environment.

WinPython

A free Python-distribution for Windows plattform, including prebuilt packages for Scientific Python.

Anaconda

Completely free enterprise-ready Python distribution for large-scale data processing, predictive analytics, and scientific computing

Python Anywhere

PythonAnywhere makes it easy to create and run Python programs in the cloud. You can write your programs in a web-based editor or just run a console session from any modern web browser.