I have pip installed a library (intelhex) with Python 3.5.1, which also places a few scripts in the Scripts subdirectory of the Python installation:

>dir "%pythonpath%"\hex2*
 Volume in drive C is System
 Volume Serial Number is 0000-ABCD

 Directory of C:\Program Files\Python35\Scripts

09.10.2016  08:13             4.698 hex2bin.py
09.10.2016  08:13             4.563 hex2dump.py
               2 File(s)          9.261 bytes
               0 Dir(s)  55.359.901.696 bytes free

One could assume that PYTHONPATH mentioned in the Python on Windows documentation for environment variables might be used for searching scripts, but Python does not find the script if the working directory is another:

>python hex2bin.py flash.hex
python: can't open file 'hex2bin.py': [Errno 2] No such file or directory

PYTHONPATH is intended only as search path for importing modules : https://stackoverflow.com/questions/19917492/how-to-use-pythonpath

Is there a method to use a given path as search path for the Python interpreter?


From: http://pythonhosted.org/IntelHex/part1-3.html#note-for-windows-users

Note for Windows users

Please note that for historical reasons IntelHex library doesn’t use setuptools for installation task, therefore we don’t create exe-wrappers for helper scripts as hex2bin.py, bin2hex.py and other mentioned in this documentation (see section Convenience Scripts).

You can find these scripts in your python Script directory (usually C:\PythonXY\Scripts). You need either to create batch file to run them, or use Python interpreter:

python C:\PythonXY\Scripts\hex2bin.py ...

First ensure that you've changed directories to the current directory that has "hex2bin.py"

seeing this current error makes me believe you aren't

python: can't open file 'hex2bin.py': [Errno 2] No such file or directory (you)

python hex2bin.py

Now if this throws no errors at you, then attempt to run it with args

python hex2bin.py HexFile.hex
  • Thanks, but the question is not how the script can be run from inside its directory, but rather if there is a way to provide Python with this directory other than specifying it in the path to the script. – handle Oct 9 '16 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.