Portable Python

The work I am doing at the moment involves building lots of models and running lots of simulations. Some of the models are running in Java but most of the analysis and especially the work I am doing on machine learning is taking place in Python.

However, I do not have administrator rights on the computer I use at work, which can make installing the latest Python packages and updates difficult. So I looked around a bit at options for having my Python workspace running completely on USB, this gives me the added advantage of being able to run my projects on different computers (useful when presenting your work to colleagues!).

Portable Python was the first stop when looking for a portable version of Python and although it is not being developed anymore they provide the alternative options on their website. From this list of options I chose to use WinPython as it is fully portable and includes all the packages I needed already.

WinPython comes with the Qt graphical user interfaces and the Spyder interactive scientific development environment. I used these for a while but at home I used PyCharm and I wasn’t liking switching environments. So I browsed around looking for anyone else who was trying to get a portable Python setup with PyCharm and information was pretty slim. So now that I have my setup running I thought I should share the details, it is pretty simple and works like a charm:)

So here is how you get a portable Python with PyCharm in Windows:

  1. First download the latest versions of WinPython and PyCharm (I downloaded Community Edition).
  2. Once you have both these downloaded simply install WinPython to your USB stick (for me this is drive G:) or harddrive (this can take a while). It does not require any special permissions unless you want integration with Windows explorer.
  3. Now, the trickier part is portable PyCharm. To do this you will need to have 7-Zip installed on the computer where you are creating your portable workspace (assuming you are on Windows). 7-Zip can be downloaded for free from here.
  4. Open 7-Zip and go to your downloads directory. Now instead of extracting a zip file you will extract the exe file you downloaded from the PyCharm website. Just click on the downloaded file and extract the file to your USB.
  5. The only thing left to do now is open the portable version of PyCharm on your USB stick and tell it to use the portable version of WinPython as the interpreter. The executable can be found in the “PyCharm\bin” folder. The portable python interpreter can be selected as shown below.
  6. However, you may notice that PyCharm is still storing its settings on the computer you are using. So that all information is saved on the USB and you have a truly portable setup you need to change one more file. The file that needs to be edited is found under “PyCharm\bin\idea.properties”. Open this file with a text editor and change it as follows:
    # Use ${idea.home.path} macro to specify location relative to IDE installation home.
    # Use ${xxx} where xxx is any Java property (including defined in previous lines of this file) to refer to its value.
    # Note for Windows users: please make sure you're using forward slashes (e.g. c:/idea/system).
    # Uncomment this option if you want to customize path to IDE config folder. Make sure you're using forward slashes.
    # idea.config.path=${user.home}/.PyCharmCE/config
    # Uncomment this option if you want to customize path to IDE system folder. Make sure you're using forward slashes.
    # idea.system.path=${user.home}/.PyCharmCE/system
    # Uncomment this option if you want to customize path to user installed plugins folder. Make sure you're using forward slashes.
    # idea.plugins.path=${idea.config.path}/plugins
    # Uncomment this option if you want to customize path to IDE logs folder. Make sure you're using forward slashes.
    # idea.log.path=${idea.system.path}/log

    Here we are uncommenting the first four options and setting the paths to the PyCharm installation home folder, in our case on the USB.

That’s it! You should now be able to run a completely portable Python workspace with PyCharm as your workspace environment. I hope this helps some more people get up and running with Python and PyCharm! In a future post I will explain how to get a portable Git setup on the same USB so that you have complete version control of your projects and everything is properly backed up.

UPDATE: Article on running a portable Git setup is now posted here!

3 thoughts on “Portable Python”

Leave a Reply to Greg Cancel reply

Your email address will not be published.