【问题标题】:VPython: How to fix "NameError: name '__server' is not defined"?VPython:如何修复“NameError:名称'__server'未定义”?
【发布时间】:2020-03-09 14:24:14
【问题描述】:

我在使用 VPython 7.6.1 时遇到了一些问题。每次我想运行一行简单的代码时,我都会遇到同样的错误:

NameError: name '__server' is not defined

代码如下:

from vpython import *
box()

我浏览了其他帖子,但没有一个解决方案对我有用:

Pyo in Python; name 'Server' not defined

Error running Vpython in Spyder (NameError: name 'gsprint' is not defined)

我更改了 python 文件的名称,我重新安装了 Anaconda 并更新了我的 Python 和 VPython 版本。我正在将 Spyder 与 Anaconda 和 Python 3.7.6 一起使用。

另外,VPython 的图形使用 TKinter,所以我将图形设置更改为 TKinter,但仍然出现相同的错误。

这里有没有其他人发生过这种情况?您对如何修复它或我在这里做错了什么有任何线索吗?

这里是详细的错误:

Python 3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 7.12.0 -- An enhanced Interactive Python.

runfile('C:/Users/lponcin/Google Drive/simplex/code_orbito.py', wdir='C:/Users/lponcin/Google Drive/simplex')
Traceback (most recent call last):

  File "C:\Users\lponcin\Google Drive\simplex\code_orbito.py", line 9, in <module>
    box()

  File "C:\Users\lponcin\Anaconda3\lib\site-packages\vpython\vpython.py", line 1099, in __init__
    super(box, self).setup(args)

  File "C:\Users\lponcin\Anaconda3\lib\site-packages\vpython\vpython.py", line 579, in setup
    super(standardAttributes, self).__init__()

  File "C:\Users\lponcin\Anaconda3\lib\site-packages\vpython\vpython.py", line 236, in __init__
    from .no_notebook import _

  File "C:\Users\lponcin\Anaconda3\lib\site-packages\vpython\no_notebook.py", line 272, in <module>
    __w = threading.Thread(target=__server.serve_forever)

NameError: name '__server' is not defined

【问题讨论】:

    标签: python python-3.x anaconda vpython


    【解决方案1】:

    __server 在文件的第 234 行创建

    https://github.com/vpython/vpython-jupyter/blob/master/vpython/no_notebook.py

    也许您遇到了一个未被检测到的异常。尝试删除围绕此代码创建服务器的 try except 语句,以查看您的系统可能存在什么问题。

    【讨论】:

    • 我从第 224 行到第 240 行删除了 try 和 exept 语句,但仍然遇到同样的错误
    • 如果您在将 print(__server) 分配给 HTTPServer 之后执行它,您会看到什么?
    • 顺便说一下,VPython 的图形不使用 TKinter;它使用作为浏览器组件的 WebGL 3D 图形库。另一种可能性:您是使用 pip 还是使用 conda install -c vpython vpython 安装 VPython(首选)?
    • 我会评论说,对于 VPython 问题,最好在 VPython 论坛上发帖,与在 stackoverflow 上发帖相比,有更多的 VPython 用户会看到您的问题:groups.google.com/forum/?fromgroups&hl=en#!forum/…
    猜你喜欢
    • 2019-09-07
    • 1970-01-01
    • 1970-01-01
    • 2022-11-13
    • 2017-08-30
    • 2021-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多