简体   繁体   English

如何使用Python3.5来解决cPickle的Python2.7错误?

[英]How to use Python3.5 in order to get around Python2.7 bug with cPickle?

I need to use Python3.x in order to work around the following bug with cPickle . 我需要使用Python3.x来解决cPickle的以下错误。 The task needs to be completed soon. 该任务需要尽快完成。

I'm running into the following error using cPickle with Python 2.7.10 . 我在Python 2.7.10使用cPickle Python 2.7.10以下错误。 In fact, it's a bug which was only solved with Python3.x 实际上,这是一个仅通过Python3.x解决的错误

http://bugs.python.org/issue11564 http://bugs.python.org/issue11564

So, I installed Python3.5. 因此,我安装了Python3.5。 Now, the script doesn't run, as I do not have modules installed for Python3, eg 现在,该脚本无法运行,因为我没有为Python3安装模块,例如

     import matplotlib.pyplot as plt 
ImportError: No module named 'matplotlib

How should users begin downloading all the modules installed in Python 2.7 to Python 3.5? 用户应该如何开始将Python 2.7中安装的所有模块下载到Python 3.5?

pip freeze can do the work of mirroring package setups from one Python install to another. pip freeze可以完成将软件包设置从一个Python安装镜像到另一个安装的工作。

Assuming pip is installed for both versions of Python (we'll name them pip2 and pip3 , you may need to use qualified paths to each depending on OS and configuration), you'd just do: 假设为两个版本的Python安装了pip (我们将它们pip2命名为pip2pip3 ,您可能需要使用合格的路径,具体取决于操作系统和配置),您只需执行以下操作:

pip2 freeze > requirements.txt
pip3 install -r requirements.txt

That will install the same package and version for each package installed under the Py2 install in your Py3 install. 这将为您在Py3安装中的Py2安装下安装的每个软件包安装相同的软件包和版本。 See the pip freeze docs for switches to tweak the output. 有关调整输出的开关,请参见pip freeze文档 I believe you could also delete the ==xyz part of each requirement if you want the latest version instead of the same version. 我相信,如果要最新版本而不是同一版本,也可以删除每个要求的==xyz部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM