首页 \ 问答 \ 无法安装python-chess:“UnboundLocalError:在赋值之前引用的局部变量'distclass'”(Failure to install python-chess: “UnboundLocalError: local variable 'distclass' referenced before assignment”)

无法安装python-chess:“UnboundLocalError:在赋值之前引用的局部变量'distclass'”(Failure to install python-chess: “UnboundLocalError: local variable 'distclass' referenced before assignment”)

我正在尝试安装python-chess (Windows 7上的Python 2.7)。

我收到以下错误:

C:\Users\Jeroen>pip install python-chess
Collecting python-chess
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may caus
e the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL con
nections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Using cached python-chess-0.13.2.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "c:\users\jeroen\appdata\local\temp\pip-build-2eph1o\python-chess\setup.py", line 91, in <module>
        "Topic :: Software Development :: Libraries :: Python Modules",
      File "c:\python27\lib\distutils\core.py", line 98, in setup
        klass = distclass
    UnboundLocalError: local variable 'distclass' referenced before assignment

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in c:\users\jeroen\appdata\local\temp\pip-build-2eph1o\python-chess\

当我再次重新运行pip install python-chess时, SNIMissingWarning不再出现,但UnboundLocalError仍然存在。

编辑

评论中的问题答案:

Python 2.7.3 |EPD_free 7.3-2 (32-bit)| (default, Apr 12 2012, 14:30:37) [MSC v.1500 32 bit (Intel)] on win32
Type "credits", "demo" or "enthought" for more information.
>>> import distutils
>>> print distutils.__version__
2.7.3
>>>

第90行的C:\Python27\Lib\distutils\core.py如下所示:

global _setup_stop_after, _setup_distribution

# Determine the distribution class -- either caller-supplied or
# our Distribution (see below).
klass = distclass
if klass:
    del distclass
else:
    klass = Distribution

if 'script_name' not in attrs:
    script_name = os.path.basename(sys.argv[0])
if 'script_args' not in attrs:
    script_args = sys.argv[1:]

I'm trying to install python-chess (Python 2.7 on Windows 7).

I get the following error:

C:\Users\Jeroen>pip install python-chess
Collecting python-chess
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may caus
e the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL con
nections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Using cached python-chess-0.13.2.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "c:\users\jeroen\appdata\local\temp\pip-build-2eph1o\python-chess\setup.py", line 91, in <module>
        "Topic :: Software Development :: Libraries :: Python Modules",
      File "c:\python27\lib\distutils\core.py", line 98, in setup
        klass = distclass
    UnboundLocalError: local variable 'distclass' referenced before assignment

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in c:\users\jeroen\appdata\local\temp\pip-build-2eph1o\python-chess\

When I rerun pip install python-chess once more, the SNIMissingWarning doesn't appear any more, but the UnboundLocalError is still there.

Edit

Answers to the questions in the comments:

Python 2.7.3 |EPD_free 7.3-2 (32-bit)| (default, Apr 12 2012, 14:30:37) [MSC v.1500 32 bit (Intel)] on win32
Type "credits", "demo" or "enthought" for more information.
>>> import distutils
>>> print distutils.__version__
2.7.3
>>>

and C:\Python27\Lib\distutils\core.py around line 90 looks like this:

global _setup_stop_after, _setup_distribution

# Determine the distribution class -- either caller-supplied or
# our Distribution (see below).
klass = distclass
if klass:
    del distclass
else:
    klass = Distribution

if 'script_name' not in attrs:
    script_name = os.path.basename(sys.argv[0])
if 'script_args' not in attrs:
    script_args = sys.argv[1:]

原文:https://stackoverflow.com/questions/36362253
更新时间:2019-07-05 04:25

最满意答案

正如Martijn Pieters在评论中正确推断的那样,我的Python安装已经被破坏了。 我安装了最新版本的Python(2.7.11),现在一切正常。


As Martijn Pieters correctly deduced in the comments, my Python install got somehow corrupted. I installed the latest version of Python (2.7.11) and now everything works fine.

2016-04-01

相关问答

更多

在赋值之前引用unboundlocalerror局部变量'i'(unboundlocalerror local variable 'i' referenced before assignment)

在函数内声明global关键字以访问全局而不是局部变量。 即 def dubleIncrement(): global j j = j+2 def increment(): global i i = i+1 请注意,当您在if语句中声明i = 0和j = 0时,这是设置全局变量,但由于它超出了任何函数的范围,因此不必在此处使用global关键字。 理想情况下,您应尽量避免使用全局变量,并尝试将变量作为参数传递给函数(想想当您决定在其他函数中再次使用变量名i和j时 ...

分配前引用的局部变量'周长'?(local variable 'perimeter' referenced before assignment?)

以下行失败,因为您在定义之前尝试在右侧使用perimeter - perimeter = (length * 2) + (perimeter * 2) 我真的不认为你想在那里使用外围。 我相信你想在那里使用width (因为这将是矩形周长的正确公式),因为 - perimeter = (length * 2) + (width * 2) 此外,当您访问length或width ,您正在访问全局变量,您应该访问self.length和self.width ,以便您访问该特定实例的长度和宽度 - ...

分配前引用的MySQLdb错误局部变量(与平常不同)(MySQLdb error local variable referenced before assignment (different than usual))

问题是只有在您输入for循环时才会分配item for item in data['items']: ... 如果data['items']为空,则您永远不会这样做,并且item仍然未分配。 The issue is that item is only assigned when you enter the for loop for item in data['items']: ... If data['items'] is empty, you never do so, an ...

Python 错误警告 local variable 'a' referenced before assignment

在f2()里面加一句:nonlocal a 就可以,强制的把a声明成a非本地的局部变量

类被视为函数中的变量[重复](Class is treated as a variable in function [duplicate])

在你的main函数中,你做一个循环: for order in orders: ... 这是对order的隐藏赋值,导致编译器将order标记为局部变量,因此UnboundLocalError: local variable 'order' referenced before assignment了UnboundLocalError: local variable 'order' referenced before assignment 编辑: 正如@Rawing的评论所指出的那样,如果 ...

参数传递给Python中的嵌套函数(Parameters passed to nested Function in Python)

在函数内部进行赋值时,解释器假定左侧的名称是该函数中的本地引用,因此将该名称定义为该特定函数的本地名称(这也适用于嵌套函数)。 因此,当您在实际分配变量result之前尝试访问变量result时,会得到UnboundLocalError 。 显示此问题的最简单示例 - >>> c = 10 >>> def a(): ... c = c + 10 ... >>> a() Traceback (most recent call last): File "<stdin>", line 1, ...

相关文章

更多

最新问答

更多
  • Android宽度:100%修复(网站接管问题)(Android width:100% fix (website takeover issue))
  • C ++函数/方法设计的良好实践(Good practice in C++ function/method design)
  • 计算其他表中不存在的所有记录 - SQL查询(Count all records that does not exist to other table - SQL Query)
  • 为什么我要用JPA共享ID?(Why do I get shared Ids with JPA?)
  • asp.net - 如何显示来自html格式的数据行的字段(asp.net - how to display a field from data row that is in html format)
  • 我们如何使用ActiveRecord从连接表中删除行?(How can we delete rows from a join table by using ActiveRecord?)
  • ng-class搞乱了类的顺序(ng-class messing with the order of classes)
  • oracle 12g无效数字错误(oracle 12g invalid number error)
  • 更改ng-src值onclick(Change ng-src value onclick)
  • 如何在android中自动添加自定义依赖项以创建新项目?(How to add custom dependencies automatically in android for ever a new project is created?)
  • datetime函数在PHP中(datetime function in php)
  • 在javascript中获取会话数组的值(in javascript get the value of a session array)
  • 如何在UTF8中编译LaTeX?(How can I compile LaTeX in UTF8? [closed])
  • Rspec:“array.should == another_array”,但不用担心订单(Rspec: “array.should == another_array” but without concern for order)
  • Logcat错误:无法在android片段中加载视图(Logcat error: unable to load view in android fragments)
  • JavaFX的。(JavaFX. Adding items to the list in different threads is not working)
  • 从GDATA日历资源迁移到Google Calendar Resource api(Migrate from GDATA calendar resource to Google Calendar Resource api)
  • SSRS 2008 - 以零情景处理分割(SSRS 2008 - Dealing with division by zero scenarios)
  • 我如何以编程方式添加一个listView列标题的点击事件(How can I add a listView column header a click event programmatically)
  • Wxpython:无法检索有关列表控件项XXX的信息(Wxpython: Couldn't retrieve information about list control item XXX)
  • 使用Tortoise SVN在SVN存储库中移动目录(Move Directory across SVN repository using Tortoise SVN)
  • 天蓝色服务结构集群中的web api无状态服务是否在一段时间不活动后进入休眠状态?(Do web api stateless services in azure service fabric cluster go to sleep after a period of inactivity?)
  • 我可以设置intelliJ来突出显示PHP编码风格吗?(Can I set intelliJ to highlight php coding style?)
  • 用javafx创建一个Truetype字体文件(Creating a Truetype Font file with javafx)
  • Spring ftp配置错误(Spring ftp configuration is wrong)
  • 使用gsub去除多个字符(Using gsub to strip multiple characters)
  • 续订推送证书并保持当前的App Store App正常工作(Renew Push certificate and keep current App Store App working)
  • js:ES5和ES6之间关于'this'关键字用法的一个令人困惑的观点(js: one confusing point about 'this' keyword usage between ES5 and ES6)
  • window.onload vs $(document).ready()(window.onload vs $(document).ready())
  • 在Swift中,如何声明一个符合一个或多个协议的特定类型的变量?(In Swift, how can I declare a variable of a specific type that conforms to one or more protocols?)