Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pycharm python控制台套接字.gaierror_Python_Pycharm - Fatal编程技术网

Pycharm python控制台套接字.gaierror

Pycharm python控制台套接字.gaierror,python,pycharm,Python,Pycharm,我在OS X Yosemite上运行Pycharm 4.5.3(10.10.3)。我创建了一个简单的python程序,并尝试打开python控制台,得到了以下堆栈跟踪错误: /usr/bin/python -u /Applications/PyCharm.app/Contents/helpers/pydev/pydevconsole.py 59286 59287 Error starting server with host: localhost, port: 59286, client_por

我在OS X Yosemite上运行Pycharm 4.5.3(10.10.3)。我创建了一个简单的python程序,并尝试打开python控制台,得到了以下堆栈跟踪错误:

/usr/bin/python -u /Applications/PyCharm.app/Contents/helpers/pydev/pydevconsole.py 59286 59287
Error starting server with host: localhost, port: 59286, client_port: 59287
Unhandled exception in thread started by <function start_server at 0x100d9bd70>
Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevconsole.py", line 283, in start_server
    server = XMLRPCServer((host, port), logRequests=False, allow_none=True)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SimpleXMLRPCServer.py", line 593, in __init__
    SocketServer.TCPServer.__init__(self, addr, requestHandler, bind_and_activate)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 419, in __init__
    self.server_bind()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 430, in server_bind
    self.socket.bind(self.server_address)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
Couldn't connect to console process.

我是python新手,在同一个问题上纠缠了半天。通过将主机设置为127.0.0.1,最终解决了此问题。 如果您有相同的问题,可以通过以下方式解决:

  • 在pycharm中打开pydevconsole.py,导航到主脚本部分并找到以下行:
    pydevconsole.StartServer(pydev_localhost.get_localhost(),int(port),int(client_port))

  • 按住ctrl键并单击函数“get_localhost()”,以导航到其源:

  • \u cache=None def get\u localhost():“”“

    应在ipv4中返回127.0.0.1,在ipv6中返回::1


    我相信这个问题是由这个函数返回的“localhost”引起的,让它成为“127.0.0.1”解决了这个问题。

    我在OS X El Capitan上遇到了这个问题,运行的是Pycharm 2016.2

    在任何打开的编辑器中:
    /Applications/PyCharm.app/Contents/helpers/pydev/pydevconsole.py

    如果您通过Finder导航,请右键单击Pycharm.app文件并选择“显示包内容”以访问路径

    查找行:

    pydevconsole.start_server(pydev_localhost.get_localhost(), int(port), int(client_port))
    
    将其更改为:

    pydevconsole.start_server('127.0.0.1', int(port), int(client_port))
    
    重新启动Pycharm并选择工具->Python控制台

    然后您应该看到:

    Users/.../env/bin/python /Applications/PyCharm.app/Contents/helpers/pydev/pydevconsole.py 56582 56583
    PyDev console: starting.
    
    
    import sys; print('Python %s on %s' % (sys.version, sys.platform))
    sys.path.extend(['/Users/...'])
    
    Python 3.5.0 (default, Dec  1 2015, 12:50:23) 
    [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.1.76)] on darwin
    

    到目前为止给出的答案没有找到根本原因,这可能是因为您的OS X
    /etc/hosts
    文件中没有包含:127.0.0.1 localhost的条目

    使用以下行更新主机文件:
    
    127.0.0.1本地主机
    

    (您需要使用sudo),然后重新启动pyCharm。除非您知道自己在做什么,否则编辑IDE源代码不是一个好主意。

    127.0.0.1有效吗?您是否也可以发布引发此异常的程序的相关部分。@Totem这是用于启动pydev控制台的内部pycharm脚本,因此我无法更改内部代码。我在main中查看了他们的源代码,并在main代码框中发布了这些代码。@haleemuli这就是与程序相关的所有内容。只需在PyCharm工具栏中单击一下,就会抛出这个。我自己没有写过代码来实现这一点。
    pydevconsole.start_server('127.0.0.1', int(port), int(client_port))
    
    Users/.../env/bin/python /Applications/PyCharm.app/Contents/helpers/pydev/pydevconsole.py 56582 56583
    PyDev console: starting.
    
    
    import sys; print('Python %s on %s' % (sys.version, sys.platform))
    sys.path.extend(['/Users/...'])
    
    Python 3.5.0 (default, Dec  1 2015, 12:50:23) 
    [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.1.76)] on darwin