The Python Oracle

ImportError: No module named test_data, but test_data.py in same directory as test.py under PyCharm using virtualenv

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Industries in Orbit Looping

--

Chapters
00:00 Question
01:25 Accepted answer (Score 4)
01:48 Answer 2 (Score 3)
02:16 Thank you

--

Full question
https://stackoverflow.com/questions/1043...

Answer 1 links:
[PyCharm 2.5.1 RC]: http://confluence.jetbrains.net/display/...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #import #virtualenv #pycharm #unittest2

#avk47



ACCEPTED ANSWER

Score 4


The work around i use is:

import sys
import os
try:
    import test_data
except ImportError:
    sys.path.append(os.path.dirname(__file__))
    try:
        import test_data
    finally:
        sys.path.remove(os.path.dirname(__file__))

A friend told me that one can also add the directory entries to some include directories.




ANSWER 2

Score 3


Please try PyCharm 2.5.1 RC, there was a bug with sys.path building (it contained incorrect, duplicated project source directory).

If it's not the case, you can mark additional directories as Source in Preferences | Project Structure or add them to the Paths in the Python Interpreters.