本文介绍了相同的解释器(?),Spyder中的软件包版本不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了这个导入错误,它是这个answer 表示发生此错误是因为requests软件包已过期.我使用pip更新了程序包,但仍然遇到相同的错误.因此,我尝试了from requests.utils import to_native_string,令我惊讶的是,它在命令提示符shell或IDLE中都可以正常工作,但是在Spyder中引发了错误.我检查了requests软件包的版本:

I got this import error, which as this answer indicates occurs because the requests package is out of date. I updated the package using pip, but still got the same error. So I tried from requests.utils import to_native_string, which to my surprise works just fine in either the command prompt shell or IDLE, but throws an error in Spyder. I checked the version of the requests package:

import requests
print(requests.__version__)

Spyder('1.2.3')中的版本号确实与IDLE或cmd shell('2.7.0')中的版本号不同.我不知为何要解释为什么会这样,因为Spyder指向C:\Python27\python.exe处的同一个解释器,并且如果我检查所使用的python版本:

The version number in Spyder ('1.2.3') is indeed different from the version number in IDLE or the cmd shell ('2.7.0'). I am a loss to explain why this would be the case, however, because Spyder points to the same interpreter at C:\Python27\python.exe and if I check the version of python being used:

import sys
print(sys.version)

我到处都得到相同的结果:'2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]'.

I get the same result everywhere: '2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]'.

推荐答案

我将检查两个可能的问题:

I would check out two different possible issues:

1)确保已删除正在导入请求的模块的.pyc文件-我相信Spyder中有一项设置可确保每次称为UMD时都重新加载解释器?

1) Make sure that the .pyc file of the module that is importing requests is deleted - I believe there is a setting in Spyder to ensure the interpreter gets reloaded each time called the UMD?

2)即使指定了解释器,也请确保也指定了Spyder使用的站点程序包.

2) Even though the interpreter is specified, make sure that the site-packages that Spyder is using is also specified.

有可能在安装Spyder时创建了一个虚拟环境,该环境在安装时复制了系统站点程序包的内容.当您可能正在更新系统软件包时,也许Spyder正在查看的虚拟环境没有被更新?

It is possible that when Spyder was installed, it created a virtual env that copied the contents of the system site-packages at the time of installation. While you may be updating the system packages, perhaps the virtual env that Spyder is looking at is not being updated?

这篇关于相同的解释器(?),Spyder中的软件包版本不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 23:19