我的代码行之一是
import yaml
它是使用pip install pyyaml
安装在python3.7上的
出现以下错误
Traceback (most recent call last):
File "C:/code/EPMD/Kodex/Applications/EPMD-Software/Sandbox/peer_changing_send_rate.py", line 1, in from TestPeer.TestPeerChangingSendRate import TestPeerChangingSendSpeed File "C:\code\EPMD\Kodex\Applications\EPMD-Software\TestPeer\TestPeerChangingSendRate.py",
line 1, in from .TestPeer import TestPeer File "C:\code\EPMD\Kodex\Applications\EPMD-Software\TestPeer\TestPeer.py",
line 4, in from BaseProcess.ZmqPeerClass import ZmqPeer File "C:\code\EPMD\Kodex\Applications\EPMD-Software\BaseProcess\ZmqPeerClass.py",
line 2, in from .ZmqPublisherClass import ZmqPublisher File "C:\code\EPMD\Kodex\Applications\EPMD-Software\BaseProcess\ZmqPublisherClass.py",
line 10, in from . import ZmqProcessClass File "C:\code\EPMD\Kodex\Applications\EPMD-Software\BaseProcess\ZmqProcessClass.py",
line 5, in from .ConfigBaseClass import ConfigBase File "C:\code\EPMD\Kodex\Applications\EPMD-Software\BaseProcess\ConfigBaseClass.py",
line 3, in import yaml File "C:\code\EPMD\Kodex\venv\lib\site-packages\yaml__init__.py", line 9, in from .dumper import * File "C:\code\EPMD\Kodex\venv\lib\site-packages\yaml\dumper.py", line 6, in from .representer import * File "C:\code\EPMD\Kodex\venv\lib\site-packages\yaml\representer.py", line
263, in SafeRepresenter.add_representer(datetime.date, AttributeError: module 'datetime' has no attribute 'date'
如何让import yaml
工作
您可能在错误消息中显示的一个目录中有一个名为
datetime.py
的文件(很可能是C:/code/EPMD/Kodex/Applications/EPMD-Software/Sandbox/
),如果您这样做了,那么您需要将它重命名为不会影响任何其他Python模块的文件原因是它屏蔽了实际的
datetime
模块,因为当前工作目录中的文件/目录/模块优先于安装在site-packages
目录中的模块(内置和安装的模块所在目录)。如果两个位置都包含a
模块,则import a
将从site-packages
导入本地a
模块,而不是(可能)预期的a
模块当
yaml\representer.py
执行import datetime
操作时,它导入了没有date
属性的datetime.py
文件/模块,这就是它后来尝试使用datetime.date
时引发AttributeError
的原因相关问题 更多 >
编程相关推荐