ImportError: there is no module named test_data, but test_data.py is in the same directory as test.py in PyCharm using virtualenv

In test.py, I am trying to import test_data:

import unittest2 import re from test_data import receipt1_example 

test_data.py is in the same directory as test.py. I get the following error:

/Users/ahammond/.virtualenvs/ric2.6/bin/python2.6 /Applications/PyCharm.app/helpers/pycharm/utrunner.py / Users / ahammond / src / hackfest _spring_2012 / parse_me / test.py :: test true Testing began at 11:30 ... Traceback (last last call):
File "/Applications/PyCharm.app/helpers/pycharm/utrunner.py", line 121, at module = loadSource (a [0]) File "/Applications/PyCharm.app/helpers/pycharm/utrunner.py", line 44, in loadSource module = imp.load_source (moduleName, fileName) File "/Users/ahammond/src/hackfest_spring_2012/parse_me/test.py", line 4, in from test_data import receipt1_example ImportError: There is no module named test_data p >

Process terminated with exit code 1

As you can see, I am running this under pycharm using virtualenv. Here is a screenshot of the configuration:

Pycharm debug configuration

+6
source share
2 answers

The work 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 you can add directory entries to some included directories.

+4
source

Try PyCharm 2.5.1 RC , an error occurred while building sys.path (it had an incorrect duplicated project source directory).

If this is not the case, you can mark additional directories as Source in Preferences | Project Structure or add them to Outlines in Python Interpreters .

+3
source

Source: https://habr.com/ru/post/914837/


All Articles