Bram Fran
Bram Fran

Reputation: 113

KeyError: 'PYTHONPATH', how can I fix PYTHONPATH? (Python 3.5.2)

I have seen this post asked before in stackoverflow but it was 4 years ago (How to fix the python path) so I am not sure wether this is the right solution because I am using a newer version of python (3.5.2). This is what I see in a Python Shell:

Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import os
>>> os.environ['PYTHONPATH'].split(os.pathsep)
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
os.environ['PYTHONPATH'].split(os.pathsep)
File "C:\Users\John\AppData\Local\Programs\Python\Python35\lib\os.py", line 725, in __getitem__
raise KeyError(key) from None
KeyError: 'PYTHONPATH'

I want to find the pythonpath.So, how can I fix this error?

Upvotes: 0

Views: 9332

Answers (3)

hafiz031
hafiz031

Reputation: 2720

First of all make sure if you have any environment variable with this name. I also got an error like this. I used PATH instead of PYHONPATH and this worked for me. I am working on Ubuntu btw.

Upvotes: 0

be_good_do_good
be_good_do_good

Reputation: 4441

There is no PYTHONPATH variable in your OS Environemental variables. Hence the error.

It is not created by Python installation (atleast in windows). You have to create one variable.

To check if there is one such environmental variable, type below command:

SET PYTHONPATH

You can also create and set it using below command

SETX PYTHONPATH <your desired path>

Upvotes: 1

napuzba
napuzba

Reputation: 6298

You may want to check sys.path

A list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default.

Upvotes: 0

Related Questions