Sublime Text 3: Anaconda package error connection to localhost timed out

十年热恋 提交于 2021-02-06 10:52:07

问题


I am getting a bizarre error message when starting up sublime text 3.

upon startup, I get the error below.

Here's some background on my system:

Windows 10

Sublime Text 3 (Anaconda Package installed through Sublime Text package installer)

From CMD:

C:\Users\joshu>where python
C:\cygwin64\bin\python
C:\Users\joshu\Anaconda3\python.exe

C:\Users\joshu>which python
/usr/bin/python

C:\Users\joshu>python --version
Python 3.5.2 :: Anaconda 4.2.0 (64-bit)

From sublime text 3 console:

sys.version
'3.3.6 (default, Sep 22 2016, 23:32:57) [MSC v.1600 64 bit (AMD64)]'

sys.path

['C:\\Users\\joshu\\AppData\\Roaming\\Sublime Text 3\\Installed Packages\\AutoPEP8.sublime-package\\sublimeautopep8lib\\packages_py3', 'C:\\Program Files\\Sublime Text 3', 'C:\\Program Files\\Sublime Text 3/python3.3.zip', 'C:\\Users\\joshu\\AppData\\Roaming\\Sublime Text 3\\Packages', 'C:\\Users\\joshu\\AppData\\Roaming\\SUBLIM~1\\Packages\\pygments\\all', 'C:\\Users\\joshu\\AppData\\Roaming\\SUBLIM~1\\Packages\\coverage\\ST3_WI~2', 'C:\\Users\\joshu\\AppData\\Roaming\\SUBLIM~1\\Packages\\MARKUP~1\\all', 'C:\\Users\\joshu\\AppData\\Roaming\\SUBLIM~1\\Packages\\PYTHON~1\\st3', 'C:\\Users\\joshu\\AppData\\Roaming\\SUBLIM~1\\Packages\\PYTHON~2\\all', 'C:\\Users\\joshu\\AppData\\Roaming\\SUBLIM~1\\Packages\\mdpopups\\st3', 'C:\\Users\\joshu\\AppData\\Roaming\\Sublime Text 3\\Packages\\coverage\\st3_windows_x64']

The first problem is that I don't know how to "check that there is Python process executing the anaconda jsonserver.py script ".

But ultimately I am at a lost on how to fix this issue.

My 'test' to see if anaconda was working was to try importing Numpy (which didn't work.. no module detected).

I did paste the following code into the sublime text 3 console.. didn't look like anything happened:

import socket; socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect(("localhost", 59552))

回答1:


In the menu:

Preferences > Package Settings > Anaconda > Settings - User

If your user settings file is empty, write:

{
    "swallow_startup_errors": true
}

and save.

If you already have other user settings in this file, just add this one to them




回答2:


Update: I Found the jsonserver.py file by searching for it in the AppData directory under sublime text..

Sublime Text console:

import sys
print(sys.path)

copy the path to Sublime Text 3 Anaconda folder in the file exploere, then I searched for jsonserver.py

When I tried to open the file, it would close itself. Not sure if that was a good or bad thing.

Ultimately I removed then reinstalled the Anaconda package. That seemed to fix the issue (although I am unsure of the root cause :/ )




回答3:


1. Note

I think, that this problem may arise by another reasons, than described in my answer. And you will need in another solutions.

But my solution works for me personally.


2. Answer

Don't set "jsonserver_debug": true in settings, if you don't run jsonserver.py manually.

If "jsonserver_debug": true, you need python -B anaconda_server/jsonserver.py -p test 9999 DEBUG in Anaconda folder, that Anaconda works correct.


3. Demonstration

3.1. Unexpected behavior

If "jsonserver_debug": true:

True

If I open .py file:

    Anaconda doesn't work (not autoformat file in example).

3.2. Expected behavior

If "jsonserver_debug": false:

False

Anaconda successful autoformat example file.


4. Environment

My environment in time, when I wrote this answer:

  • Windows 10 Enterprise LTSB 64-bit EN,
  • Sublime Text Build 3143 portable,
  • Python 3.6.4, installed globally,
  • Anaconda 2.1.25.



回答4:


I had the same problem on OS X and tried almost every solution you can find on the web. the problem seems to be related to a delay in json server response time so that when it exceeds 2 Seconds you get the error.

there are two possible workarounds:

first method is by increasing the time out:

change the line 33 in /anaconda_lib/workers/local_worker.py

from

timeout = get_socket_timeout(0.2)

to

timeout = get_socket_timeout(1)

this should help you with the error by giving a little more time to perform server checks before throwing an error.

the second method is by changing permissions on anaconda log file to make sure it is owned by your user, as stated by the original contributer:

Anaconda behaves slowly and jsonserver crashes

If you are in POSIX systems (Linux or OS X) take a look at the owner of the anaconda's jsonserver log files, they must be owned by your user or the jsonserver would be unable to start up. Log files can be found in:

GNU/Linux: ~/.local/share/anaconda/logs

OS X: ~/Library/Logs/anaconda

Windows: %APPDATA%\Anaconda\Logs

This is how I was able to resolve the issue:

1- delete ~/Library/Logs/anaconda directory

2- run sublime text and open some .py files until anaconda recreates the directory

3- give read/write permissions to that folder and its sub-directories for every user on your computer (administrator,everyone,etc...)

there is a good chance you'll have to repeat the steps above every now and then. that's what I do volunteerly before anaconda makes me to do so!

UPDATE

I've found that the problem can be caused by VPN connection as well, so that everytime I connect and disconnect this error shows up.




回答5:


I had this issue on my Mac. On a terminal I checked if the jsonserver.py was running.

$ ps aux | grep jsonserver
user1         17170   0.0  0.0  4286488    856 s001  S+   10:51am   0:00.00 grep jsonserver.py
user1         14803   0.0  0.4  4358656  74252   ??  S    10:31am   0:06.30 python -B /path/to/jsonserver.py -p cxda 51380 -e /path/to/folders/,/path/to/other/folder/ 7973
user1         14787   0.0  0.2  4312684  26444   ??  S    10:31am   0:00.53 python -B /path/to/jsonserver.py -p cxda 51357 -e /path/to/folders/,/path/to/other/folder/ 7973

The results showed I had two jsonservers running using the same port. So I disabled anaconda in Sublime using command+shift+p and searching for Package Control: Disable Package. Simply type disa and it should come up straight away.

After disabling the package, I killed the two processes.

$ kill 14803
$ kill 14787
$ ps aux | grep jsonserver
user1         17220   0.0  0.0  4277272    840 s001  S+   10:52am   0:00.00 grep jsonserver.py

Then I enabled the package via package control in sublime using command+shift+p. Enabling the package will start a new jsonserver.py. This solved the issue for me.




回答6:


Just enter this inside sublime 3 console: view -> show console

"import socket; socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect(("localhost", 50390))"

50390 is a diferent number.



来源:https://stackoverflow.com/questions/41849999/sublime-text-3-anaconda-package-error-connection-to-localhost-timed-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!