问题
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~~~
回答1:
Don't use powershell to create files being read by python. Used Vim to create __init__.py
files instead. Thanks commenters.
来源:https://stackoverflow.com/questions/45426922/when-importing-a-module-without-null-bytes-i-get-valueerror-source-code-string