真是碰到走进科学那样的灵异事件了,同一个目录下,一样的python环境,一样pyramid的服务,两个控制台窗口,一个终端可以启动,另一个终端就启动不了。
都是这一条命令
python pyramid_app.py
不能启动的终端,报错:
python pyramid_app.py
Traceback (most recent call last):
File "/Users/skywalk/work/fastapi/pyramid_app.py", line 3, in <module>
from pyramid.config import Configurator
File "/Users/skywalk/py311/lib/python3.11/site-packages/pyramid/config/__init__.py", line 8, in <module>
from pyramid.asset import resolve_asset_spec
File "/Users/skywalk/py311/lib/python3.11/site-packages/pyramid/asset.py", line 2, in <module>
import pkg_resources
File "/Users/skywalk/py311/lib/python3.11/site-packages/pkg_resources/__init__.py", line 96, in <module>
from jaraco.text import (
File "/Users/skywalk/py311/lib/python3.11/site-packages/setuptools/_vendor/jaraco/text/__init__.py", line 12, in <module>
from jaraco.context import ExceptionTrap
File "/Users/skywalk/py311/lib/python3.11/site-packages/setuptools/_vendor/jaraco/context.py", line 17, in <module>
from backports import tarfile
ImportError: cannot import name 'tarfile' from 'backports' (/Users/skywalk/py311/lib/python3.11/site-packages/backports/__init__.py)
再一看pip list,果然两个终端环境不一样:
可以启动的
WebOb 1.8.9
zope.deprecation 5.0
zope.interface 7.1.1
不可以启动的
WebOb 1.8.9
websocket-client 0.58.0
websockets 11.0.3
Werkzeug 2.2.3
wget 3.2
whatthepatch 1.0.2
wheel 0.44.0
widgetsnbextension 4.0.5
wrapt 1.14.1
wurlitzer 3.0.2
xarray 2023.6.0
xattr 0.10.1
xlwings 0.29.1
xyzservices 2022.9.0
y-py 0.5.9
yapf 0.31.0
yarl 1.8.1
ypy-websocket 0.8.2
zict 2.2.0
zipp 3.11.0
zope.deprecation 5.0
zope.interface 5.4.0
zstandard 0.19.0
但是两个环境不应该有差别啊
把前一个终端关闭后,现在打开的全部都是终端2那样,执行就报错!
尝试安装jaraco
根据报错安装的是:jaraco.context
pip list |grep jaraco
jaraco.classes 3.2.1
(base) laiweilideMacBook-Air:fastapi skywalk$ pip install jaraco.context
安装完毕后,问题解决!
标签:pyramid,Users,python,py,skywalk,报错,import,控制台,jaraco From: https://blog.csdn.net/skywalk8163/article/details/143624733