3

Python isn't importing modules!

marketing
    ├───__init__.py
    ├───analyzation\
    │   ├───__init__.py
    │   ├───analyzer.py
    ├───api\
    ├───test\
    │   ├───test_res\ (not important)
    │   ├───__init__.py
    │   ├───test_analyzer.py

Above is my folder structure. So, in analyzer.py I have a class DataSet and nothing else other than some imports from pandas and an import in a method import random.

In test_analyzer.py I have a class that subclasses unittest.TestCase. This script tries to test the following class being imported: import marketing.analyzation.analyzer (which doesn't work). The error message is the following:

Traceback (most recent call last):
  File ".\test_analyzer.py", line 1, in <module>
    import marketing.analyzation.analyzer
ValueError: source code string cannot contain null bytes

Just to make sure it wasn't some dumb vim error, I retyped analyzer.py. Spent at least 2 hours trying to fix this, and another hour surfing stackoverflow and googling, but so far I've come up with nothing. Is it because test_analyzer.py is in its own submodule?

Thanks~~~

Ry-
  • 218,210
  • 55
  • 464
  • 476
matt961
  • 31
  • 1
  • 4

2 Answers2

0

Don't use powershell to create files being read by python. Used Vim to create __init__.py files instead. Thanks commenters.

matt961
  • 31
  • 1
  • 4
0

I had similar problem with pytest.

In my case the problem was in __init__.py: the file was created in UTF-16 encoding. I changed encoding to UTF-8 and the problem disappeared.

feeeper
  • 2,865
  • 4
  • 28
  • 42