0

In one python file when I try from pandasql import sqldf it works. The path for that is

C:\Users\AmitSingh\Anaconda2\python.exe "C:/Users/AmitSingh/PycharmProjects/HelloPython.py/exercise 2"

In another file when I use the same command it gives me the error

ImportError: cannot import name sqldf

The path for this file is

C:\Users\AmitSingh\Anaconda2\python.exe C:/Users/AmitSingh/Desktop/Data/Udacity/Intro_Machine_Learning/ud120-projects/datasets_questions/explore_enron_data.py

I don't understand why? When I write import sqldf the prompt shows sqldf as an autocomplete option. But doesn't work.

Ben Morris
  • 606
  • 5
  • 24
Amit Singh Parihar
  • 527
  • 3
  • 14
  • 23

1 Answers1

0

By default, you can't. When importing a file, Python only searches the current directory, the directory that the entry-point script is running from, and sys.path which includes locations such as the package installation directory (it's actually a little more complex than this, but this covers most cases).

However, you can add to the Python path at runtime:

# some_file.py
import sys
sys.path.insert(0, '/path/to/application/app/folder')

import file
Varimax
  • 1
  • 1