简体   繁体   中英

Can't start a python console in pycharm

OS:win7 x64

When I click the "python console" tab, I get the following output. I had successfully started the python console several months ago, but now I can't.

"C:\Program Files\Python36\python.exe" "C:\Program Files\JetBrains\PyCharm 2017.2.3\helpers\pydev\pydevconsole.py" 52527 52528
PyDev console: starting.
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['D:\\2017编程\\python', 'D:/2017编程/python'])
Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2017.2.3\helpers\pydev\_pydev_bundle\pydev_console_utils.py", line 257, in add_exec
    self.finish_exec(more)
  File "C:\Program Files\JetBrains\PyCharm 2017.2.3\helpers\pydev\_pydev_bundle\pydev_console_utils.py", line 434, in finish_exec
    return server.NotifyFinished(more)
  File "C:\Program Files\Python36\lib\xmlrpc\client.py", line 1112, in __call__
    return self.__send(self.__name, args)
  File "C:\Program Files\Python36\lib\xmlrpc\client.py", line 1452, in __request
    verbose=self.__verbose
  File "C:\Program Files\Python36\lib\xmlrpc\client.py", line 1154, in request
    return self.single_request(host, handler, request_body, verbose)
  File "C:\Program Files\Python36\lib\xmlrpc\client.py", line 1166, in single_request
    http_conn = self.send_request(host, handler, request_body, verbose)
  File "C:\Program Files\Python36\lib\xmlrpc\client.py", line 1279, in send_request
    self.send_content(connection, request_body)
  File "C:\Program Files\Python36\lib\xmlrpc\client.py", line 1309, in send_content
    connection.endheaders(request_body)
  File "C:\Program Files\Python36\lib\http\client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Program Files\Python36\lib\http\client.py", line 1026, in _send_output
    self.send(msg)
  File "C:\Program Files\Python36\lib\http\client.py", line 964, in send
    self.connect()
  File "C:\Program Files\Python36\lib\http\client.py", line 936, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "C:\Program Files\Python36\lib\socket.py", line 722, in create_connection
    raise err
  File "C:\Program Files\Python36\lib\socket.py", line 713, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

Finally Solved. Add the following to your hosts if you use a local DNS server.

::1 localhost
127.0.0.1 localhost
255.255.255.255 broadcasthost
fe80::1%lo0 localhost

Some people have reported a similar issue here: https://youtrack.jetbrains.com/issue/PY-7070

To quote the answer:

User was able to fix the problem by changing the DNS server from the local one (provided by the access point) to Google DNS server (8.8.8.8).

It looks like Mac OS Lion and later doesn't use /etc/hosts file first, giving priority to DNS servers, hence it's possible that localhost may not resolve (though, it's unclear why it doesn't fall back to /etc/hosts).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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