我的代码行之一是
import yaml
已使用pip install pyyaml
在python 3.7上安装
出现以下错误
追踪(最近通话):
文件“ C:/code/EPMD/Kodex/Applications/EPMD-Software/Sandbox/peer_changing_send_rate.py”,第1行,在从TestPeer.TestPeerChangingSendRate导入TestPeerChangingSendSpeed文件“ C:\ code \ EPMD \ Kodex \ Applications \ EPMD-Software \ TestPeer \ TestPeerChangingSendRate.py”,
第1行,在从.TestPeer导入TestPeer文件“ C:\ code \ EPMD \ Kodex \ Applications \ EPMD-Software \ TestPeer \ TestPeer.py”,
第4行,在从BaseProcess.ZmqPeerClass导入ZmqPeer文件“ C:\ code \ EPMD \ Kodex \ Applications \ EPMD-Software \ BaseProcess \ ZmqPeerClass.py”,
第2行,在从.ZmqPublisherClass导入ZmqPublisher文件“ C:\ code \ EPMD \ Kodex \ Applications \ EPMD-Software \ BaseProcess \ ZmqPublisherClass.py”,
第10行,在来自。导入ZmqProcessClass文件“ C:\ code \ EPMD \ Kodex \ Applications \ EPMD-Software \ BaseProcess \ ZmqProcessClass.py”,
第5行,在从.ConfigBaseClass导入ConfigBase文件“ C:\ code \ EPMD \ Kodex \ Applications \ EPMD-Software \ BaseProcess \ ConfigBaseClass.py”,
第3行,在进口Yaml第9行中的文件“ C:\ code \ EPMD \ Kodex \ venv \ lib \ site-packages \ yaml__init __。py”来自.dumper import *在第6行的文件“ C:\ code \ EPMD \ Kodex \ venv \ lib \ site-packages \ yaml \ dumper.py”来自.representer import *文件“ C:\ code \ EPMD \ Kodex \ venv \ lib \ site-packages \ yaml \ representer.py”,行
263,在SafeRepresenter.add_representer(datetime.date,AttributeError:模块'datetime'没有属性'date'
我如何使import yaml
工作?
[您可能在错误消息中显示的目录之一(很可能是datetime.py
)中有一个名为C:/code/EPMD/Kodex/Applications/EPMD-Software/Sandbox/
的文件,如果这样做,则需要将其重命名为不会遮盖任何其他Python模块的名称。] >
原因是它掩盖了实际的datetime
模块,因为当前工作目录中的文件/目录/模块优先于site-packages
目录中安装的模块(内置和已安装模块所在的目录) 。
[当yaml\representer.py
执行import datetime
时,它导入了不具有datetime.py
属性的date
文件/模块,这就是为什么在以后尝试使用AttributeError
时引发datetime.date
的原因。