Skip to main content
improve
Source Link
CristiFati
  • 41.3k
  • 9
  • 67
  • 109
import os
import sys


print("Executable:", sys.executable)
print("Version:", sys.version)
print("CWD:", os.getcwd())
print("UName:", getattr(os, "uname", lambda: None)())
for evn in ("PATH", "PYTHONHOME", "PYTHONPATH"):
    print("{:s}: {:}".format(evn, os.environ.get(evn)))
print("sys.path:", sys.path)
import os
import sys


print("Executable:", sys.executable)
print("Version:", sys.version)
print("CWD:", os.getcwd())
print("UName:", getattr(os, "uname", lambda: None)())
for evn in ("PATH", "PYTHONPATH"):
    print("{:s}: {:}".format(evn, os.environ.get(evn)))
print("sys.path:", sys.path)
import os
import sys


print("Executable:", sys.executable)
print("Version:", sys.version)
print("CWD:", os.getcwd())
print("UName:", getattr(os, "uname", lambda: None)())
for evn in ("PATH", "PYTHONHOME", "PYTHONPATH"):
    print("{:s}: {:}".format(evn, os.environ.get(evn)))
print("sys.path:", sys.path)
improve
Source Link
CristiFati
  • 41.3k
  • 9
  • 67
  • 109
import os
import sys


print("Executable:", sys.executable)
print("Version:", sys.version)
print("CWD:", os.getcwd())
print("UName:", getattr(os, "uname", lambda: None)())
for evn in ("PATH", "PYTHONPATH"):
    print("{:s}: {:}".format(evn, os.environ.get(evn)))
print("sys.path:", sys.path)
import os
import sys


print(sys.executable)
print(sys.version)
print(os.getcwd())
print(getattr(os, "uname", lambda: None)())
print(sys.path)
import os
import sys


print("Executable:", sys.executable)
print("Version:", sys.version)
print("CWD:", os.getcwd())
print("UName:", getattr(os, "uname", lambda: None)())
for evn in ("PATH", "PYTHONPATH"):
    print("{:s}: {:}".format(evn, os.environ.get(evn)))
print("sys.path:", sys.path)
improve
Source Link
CristiFati
  • 41.3k
  • 9
  • 67
  • 109
  • According to [Python.Docs]: Modules - The Module Search Path:

    When a module named spam is imported, the interpreter first searches for a built-in module with that name. These module names are listed in sys.builtin_module_names. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path. sys.path is initialized from these locations:

    • The directory containing the input script (or the current directory when no file is specified).

    • PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).

    • The installation-dependent default (by convention including a site-packages directory, handled by the site module).

    A module might be located in the current dir, or its path might be added to ${PYTHONPATH}. That could trick users into making them believe that the module is actually installed in the current Python instance ('s site-packages). But, when running the current Python instance from a different dir (or with different ${PYTHONPATH}) the module would be missing, yielding lots of headaches

  • For a fix, check [SO]: How PyCharm imports differently than system command prompt (Windows) (@CristiFati's answer)

improve
Source Link
CristiFati
  • 41.3k
  • 9
  • 67
  • 109
Loading
improve
Source Link
CristiFati
  • 41.3k
  • 9
  • 67
  • 109
Loading
Source Link
CristiFati
  • 41.3k
  • 9
  • 67
  • 109
Loading