在命令行下from struct import pack, unpack显示正确,但是导入其他包的时候存在from struct import pack时就错误

草根caogen 2019-08-30 10:18:19
写了一个简单的python程序,一直报错
# usr/bin/python
#-*-coding: utf-8 -*-

import tensorflow as tf
import matplotlib.pylab as plt
import numpy as np

sess = tf.Session()
const = tf.constant([-2.,3.,9.,10.])
$ python3 plot_tensorflow.py

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numpy-1.18.0.dev0+09cb2bd-py3.6-macosx-10.6-intel.egg/numpy/compat/py3k.py", line 24, in <module>
import pickle5 as pickle
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pickle5/__init__.py", line 1, in <module>
from .pickle import *
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pickle5/pickle.py", line 33, in <module>
from struct import pack, unpack
ImportError: cannot import name 'pack'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numpy-1.18.0.dev0+09cb2bd-py3.6-macosx-10.6-intel.egg/numpy/core/__init__.py", line 17, in <module>
from . import multiarray
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numpy-1.18.0.dev0+09cb2bd-py3.6-macosx-10.6-intel.egg/numpy/core/multiarray.py", line 14, in <module>
from . import overrides
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numpy-1.18.0.dev0+09cb2bd-py3.6-macosx-10.6-intel.egg/numpy/core/overrides.py", line 9, in <module>
from numpy.compat._inspect import getargspec
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numpy-1.18.0.dev0+09cb2bd-py3.6-macosx-10.6-intel.egg/numpy/compat/__init__.py", line 14, in <module>
from . import py3k
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numpy-1.18.0.dev0+09cb2bd-py3.6-macosx-10.6-intel.egg/numpy/compat/py3k.py", line 26, in <module>
import pickle
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pickle.py", line 33, in <module>
from struct import pack, unpack
ImportError: cannot import name 'pack'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "plot_tensorflow.py", line 4, in <module>
import tensorflow as tf
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/__init__.py", line 28, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 27, in <module>
import ctypes
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ctypes/__init__.py", line 14, in <module>
from struct import calcsize as _calcsize
File "/Users/yangsen/Desktop/ys/yangsen/code/tensorflow/struct.py", line 5, in <module>
import numpy as np
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numpy-1.18.0.dev0+09cb2bd-py3.6-macosx-10.6-intel.egg/numpy/__init__.py", line 142, in <module>
from . import core
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numpy-1.18.0.dev0+09cb2bd-py3.6-macosx-10.6-intel.egg/numpy/core/__init__.py", line 47, in <module>
raise ImportError(msg)
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.6 from "/Library/Frameworks/Python.framework/Versions/3.6/bin/python3",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.18.0.dev0+09cb2bd" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log

- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.

Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.

Original error was: cannot import name 'pack'
...全文
345 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
草根caogen 2019-08-30
  • 打赏
  • 举报
回复
希望有你能帮忙看一下

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧