Questions tagged [sys.path]

An automatically initialized list in Python that contains the search path for modules.

In Python, sys.path is a list of the runtime locations searched when importing a module.

From the Python documentation:

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.

143 questions
0
votes
1 answer

Google app Engine with Twython Library on Python

I am trying to build a twitter app on google appengine using Python. I have used a Python Library called Twython to make the app on my Python script. However, when I try to use it in conjunction with google appengine, the application doesn't build…
0
votes
1 answer

How can I import module if I have an absolute path in Python

I need to import my module foo.py if I've got an absolute path (so module is located in "users/suv/desktop/pr1/pyth" but can be located in any different path as well) . I tried import sys MYDIR = "users/suv/desktop/pr1/pyth" …
Max_S
  • 125
  • 1
  • 1
  • 9
0
votes
1 answer

How to add a path to sys.path permanently

Let's say I have a Python file which I would like to import and use anywhere else; how can I write a Python code to insert the path of this module to sys.path permanently?
user3241727
0
votes
1 answer

Django - ImportError: cannot import name

I am having problem with 1 error, I installed all apps on Django 1.6.2 and Django 1.5.5 and having the same problem. My settings are: Django 1.5.5 INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', …
Radek
  • 1,021
  • 1
  • 17
  • 33
0
votes
1 answer

How to import a module from a directory?

On my system I have two versions of Python (to call them I type python and python2 in the command line). When I use the first version of Python, I cannot import sklearn module but I can do it in the second version of Python. I would like to use the…
Roman
  • 97,757
  • 149
  • 317
  • 426
0
votes
2 answers

Is the first entry in sys.path supposed to represent the current working directory?

I had always assumed that the first entry in sys.path by default was the current working directory. But as it turns out, on my system the first entry is the path on which the script resides. So if I'm executing a script that's in /usr/bin from…
Jason Baker
  • 171,942
  • 122
  • 354
  • 501
0
votes
0 answers

py2app -- importing external modules

Can py2app be set up such that the typical contents of a user's sys.path (when running python, not a py2app .app) are appended at the end of the path that py2app sets up? I am bundling an application with an interactive python prompt -- I would like…
ChrisB
  • 4,160
  • 6
  • 23
  • 39
-1
votes
1 answer

Why python cannot see a file after it has been moved to a sub-directory?

I had a file called mem.py in my directory and from another script I have imported: from mem import get_val Then I decided to move mem.py into funcs subdirectory. To make it visible to my script, from which I import, I have added into it: import…
Roman
  • 97,757
  • 149
  • 317
  • 426
1 2 3
9
10