When importing a module without null bytes I get ValueError: source code string cannot contain null bytes

廉价感情. 提交于 2020-01-04 05:25:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!