0

I used

>>> import sys
>>> print(sys.path)

and I get this:

['', 'C:\\Users\\HowLo\\AppData\\Local\\Programs\\Python\\Python3‌​6-32\\python36.zip',
'C:\\Users\\HowLo\\AppData\\Local\\Programs\\Python\\Python3‌​6-32\\DLLs',
'C:\\Users\\HowLo\\AppData\\Local\\Programs\\Python\\Python3‌​6-32\\lib',
'C:\\Users\\HowLo\\AppData\\Local\\Programs\\Python\\Python3‌​6-32',
'C:\\Users\\HowLo\\AppData\\Local\\Programs\\Python\\Python3‌​6-32\\lib\\site-pack‌​ages']

I am confused why this is in there:

r'C:\Users\HowLo\AppData\Local\Programs\Python\Python36-32\python36.zip'

when I try to pull it up in the File Explorer, nothing is there.

das-g
  • 9,718
  • 4
  • 38
  • 80
  • 2
    You shouldn't be getting that at all. `sys.path` returns a list of string, not a single string – theonlygusti Jan 26 '17 at 22:45
  • it is a list, ['', 'C:\\Users\\HowLo\\AppData\\Local\\Programs\\Python\\Python36-32\\python36.zip', 'C:\\Users\\HowLo\\AppData\\Local\\Programs\\Python\\Python36-32\\DLLs', 'C:\\Users\\HowLo\\AppData\\Local\\Programs\\Python\\Python36-32\\lib', 'C:\\Users\\HowLo\\AppData\\Local\\Programs\\Python\\Python36-32', 'C:\\Users\\HowLo\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages'] – Isaiah Wright Jan 26 '17 at 22:48
  • sorry, just tried to shorten it, not trying to confuse further – Isaiah Wright Jan 26 '17 at 22:48
  • And you're _absolutely 100% certain_ that the file (yes, zip archives are files) `%appdata%\Local\Programs\Python\Python-36-32\python36.zip` doesn't exist? Have you tried going to its enclosing folder? – theonlygusti Jan 26 '17 at 22:52
  • yes. would i be better off reinstalling python? – Isaiah Wright Jan 26 '17 at 22:56
  • Well basically, your problem is that that file is not there. – theonlygusti Jan 26 '17 at 22:57
  • 2
    Seriously though, this is a Q&A site. What is the Q here? – theonlygusti Jan 26 '17 at 22:57
  • 1
    So, the file isn't there, so its contents aren't actually part of your search path, so... what? Why do you care? If it *were* there, then Python modules could be located in it, but it's not, so that's moot. – Charles Duffy Jan 26 '17 at 23:00
  • 1
    I'm surprised at the vitriol here. OK, so the OP formed his question as a statement. It's not like we don't understand the implied question: "Why is there a pointer to a non-existent file or path in my `sys.path`?" It's a fair question, and one that I wanted to know. (1) No, the OP should not re-install Python, (2) Yes, the OP wants to know **why** this string pointing to a non-existent file cropped up. [Here is the best answer](https://stackoverflow.com/a/38403654/534238) that I could find. Hope it helps! – Mike Williamson Feb 15 '19 at 01:42

2 Answers2

3

sys.path stores a list of strings, each one (as you can tell) is a path to a location on your computer.

Python looks in these places to find modules your program can use (when you do import sys python is getting the sys module from one of the locations in sys.path)

Paths to .zip files are just as valid as paths to folders, python will try to unzip any archived files.


Now that you know what sys.path is, we can look at your "problem."

You've said that C:\Users\HowLo\AppData\Local\Programs\Python\Python36-32\python36.zip doesn't exist.

All this means is that python doesn't load any modules from there.

It really has no (meaningful) implications whatsoever.

theonlygusti
  • 11,032
  • 11
  • 64
  • 119
  • 2
    But why do these `.zip` file paths show up? I also have one, and I'm ignoring it because I knew, as you said, that it simply does not load any modules. However, I'd love to be able to clean up that sys.path and to understand how everything is being loaded. But even [this particularly detailed answer](https://stackoverflow.com/a/38403654/534238) didn't fully help me understand. – Mike Williamson Feb 15 '19 at 01:37
-1

The sys path can be appended with whatever path you choose. It is after all simply a list.

It is used to search for modules which are not in the current folder. More on that in the docs.

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

As initialized upon program startup, the first item of this list, path[0], is the directory containing the script that was used to invoke the Python interpreter. If the script directory is not available (e.g. if the interpreter is invoked interactively or if the script is read from standard input), path[0] is the empty string, which directs Python to search modules in the current directory first. Notice that the script directory is inserted before the entries inserted as a result of PYTHONPATH.

A program is free to modify this list for its own purposes. Only strings and bytes should be added to sys.path; all other data types are ignored during import.

Community
  • 1
  • 1
magu_
  • 4,766
  • 3
  • 45
  • 79