Saturday, 2 June 2018

VBA - Python - Console culture part 1 - setting up environment variables

So in this blog post I show a simple hello world COM class written in Python. Admittedly that post gives few details on working at the command line, let me rectify that here.

Finding the Python folder

Let's work with the same Python install as Visual Studio 2017, so I'm assuming the reader has installed the Python workload for Visual Studio 2017. If installed we can find the python folder within the Visual Studio folder, open up a new command window and type the text highlighted in blue.


Microsoft Windows [Version 10.0.17134.48]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\Simon>cd C:\Program Files (x86)\Microsoft Visual Studio

C:\Program Files (x86)\Microsoft Visual Studio>dir python.exe /s
 Volume in drive C is OS
 Volume Serial Number is D6D5-B454

 Directory of C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64

19/09/2017  17:06            93,696 python.exe
               1 File(s)         93,696 bytes

 Directory of C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\pkgs\python-3.6.2-h6679aeb_11

19/09/2017  17:06            93,696 python.exe
               1 File(s)         93,696 bytes

 Directory of C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64

03/10/2017  19:15           100,504 python.exe
               1 File(s)        100,504 bytes

     Total Files Listed:
               3 File(s)        287,896 bytes
               0 Dir(s)  2,635,719,708,672 bytes free

C:\Program Files (x86)\Microsoft Visual Studio>

So I going to use C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64 though yours may be different. Irritatingly, environment variables do not like spaces but if you convert to DOS 8.3 format then you ought to get a path that has no spaces; I wrote a program here to shorten a path, I ran this and I now get a shorter (and more cryptic ) path of C:\PROGRA~2\MICROS~4\Shared\PYTHON~1

Setting up Environment Variables

One sets up environment variables via the control panel app and a set of dialogs, here is a helping picture for those unfamiliar.

I have chosen to set up two new environment variables, %pythonpath% for the python folder, %python% for python executable, python.exe. I have also added %pythonpath% to the %PATH% variable, along with %pythonpath%\scripts which makes the pip executable reachable as well.

Remember that any changes to the environment variables need to be saved with the OK button and only command windows opened after the save will reflect the changes.

No comments:

Post a Comment