scrtlabs / catalyst

An Algorithmic Trading Library for Crypto-Assets in Python
http://enigma.co
Apache License 2.0
2.49k stars 725 forks source link

_tkinter.TclError: no display name and no $DISPLAY environment variable #39

Closed rjoshig closed 6 years ago

rjoshig commented 7 years ago

Dear Catalyst Maintainers,

Before I tell you about my issue, let me describe my environment:

Environment


* Operating System: (Windows Subsystem For Linux )--  Linux DESKTOP 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014 x86_64 x86_64 x86_64 GNU/Linux
* Python Version: Python 2.7.12
* Python Bitness: 64
* How did you install Catalyst: pip (virtual environment)
* Python packages: `$ pip freeze` 

alembic==0.7.7
backports.functools-lru-cache==1.4
bcolz==0.12.1
Bottleneck==1.0.0
certifi==2017.7.27.1
chardet==3.0.4
click==4.0
contextlib2==0.4.0
cycler==0.10.0
cyordereddict==0.2.2
Cython==0.25.2
decorator==4.0.0
empyrical==0.2.1
enigma-catalyst==0.2.dev5
idna==2.6
intervaltree==2.1.0
Logbook==0.12.5
lru-dict==1.1.4
Mako==1.0.1
MarkupSafe==0.23
matplotlib==2.1.0
multipledispatch==0.4.8
networkx==1.9.1
numexpr==2.6.1
numpy==1.13.1
pandas==0.19.2
pandas-datareader==0.2.1
patsy==0.4.0
pkg-resources==0.0.0
pyparsing==2.2.0
python-dateutil==2.4.2
python-editor==1.0.3
pytz==2016.4
requests==2.9.1
requests-file==1.4.1
requests-ftp==0.3.1
scipy==0.17.1
six==1.10.0
sortedcontainers==1.4.4
SQLAlchemy==1.0.8
statsmodels==0.6.1
subprocess32==3.2.7
tables==3.3.0
toolz==0.8.2
urllib3==1.22

Now that you know a little about me, let me tell you about the issue I am having:

Description of Issue

No able to run. It seems to be display issue.

  1. I am running Windows subsystem for Linux
  2. Connected to a VGA monitor from a laptop HDMI-VGA converter cable.

Here is how you can reproduce this issue on your machine:

## Reproduction Steps

1. Connect your laptop to VGA monitor using HDMI-VGA converter cable
2. Run command below
`catalyst run -f buy_and_hodl.py --start 2015-3-2 --end 2017-7-31 --capital-base 100000 -o bah.pickle`
...

## What steps have you taken to resolve this already?

1. `export DISPLAY=:0 `and run,same error
2.  `export DISPLAY=0.0` and run, same error
3. `export DISPLAY=:0.0` and run, same error
4. Tried different combination of `export DISPLAY`
5. Created file below

ethdev@DESKTOP { ~/.config/matplotlib }$ cat matplotlibrc backend: TkAgg


6.  Tried this one too
`echo "backend: TkAgg" > ~/.matplotlib/matplotlibrc`

# Anything else?
No additional details

Sincerely,
**mesnia**
rjoshig commented 7 years ago

Changed matplotlibrc to below:-

echo "backend: Agg" > ~/.config/matplotlib/matplotlibrc

Now it doesn't throw an error but it does not display anything either. What am i missing here?


 catalyst run -f buy_and_hodl.py --start 2015-3-2 --end 2017-7-31 --capital-base 100000 -o bah.pickle

[2017-10-14 21:25:23.349705] INFO: run_algo: running algo in backtest mode
[2017-10-14 21:25:23.499095] INFO: Loader: Loading benchmark data for 'USDT_BTC' from 2015-03-02 00:00:00+00:00 to 2017-10-03 00:00:00
[2017-10-14 21:25:27.163971] INFO: Performance: Simulated 883 trading days out of 883.
[2017-10-14 21:25:27.164118] INFO: Performance: first open: 2015-03-02 00:00:00+00:00
[2017-10-14 21:25:27.164282] INFO: Performance: last close: 2017-07-31 23:59:00+00:00
hacktek commented 7 years ago

Same issue in Ubuntu.

(catalyst-venv) root@ovh:~# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.3 LTS Release: 16.04 Codename: xenial

(catalyst-venv) root@ovh:~# catalyst run -f buy_and_hodl.py --start 2015-3-2 --end 2017-6-28 --capital-base 100000 -o bah.pickle [2017-10-18 04:34:56.553822] INFO: run_algo: running algo in backtest mode [2017-10-18 04:34:56.705316] INFO: Loader: Loading benchmark data for 'USDT_BTC' from 2015-03-02 00:00:00+00:00 to 2017-10-03 00:00:00 [2017-10-18 04:35:01.258081] INFO: Performance: Simulated 850 trading days out of 850. [2017-10-18 04:35:01.259023] INFO: Performance: first open: 2015-03-02 00:00:00+00:00 [2017-10-18 04:35:01.259226] INFO: Performance: last close: 2017-06-28 23:59:00+00:00 Traceback (most recent call last): File "/root/catalyst-venv/bin/catalyst", line 11, in sys.exit(main()) File "/root/catalyst-venv/local/lib/python2.7/site-packages/click/core.py", line 722, in call return self.main(args, kwargs) File "/root/catalyst-venv/local/lib/python2.7/site-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/root/catalyst-venv/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/root/catalyst-venv/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, ctx.params) File "/root/catalyst-venv/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke return callback(args, kwargs) File "/root/catalyst-venv/local/lib/python2.7/site-packages/catalyst/main.py", line 98, in _ return f(*args, *kwargs) File "/root/catalyst-venv/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func return f(get_current_context(), args, kwargs) File "/root/catalyst-venv/local/lib/python2.7/site-packages/catalyst/main.py", line 294, in run live_graph=live_graph File "/root/catalyst-venv/local/lib/python2.7/site-packages/catalyst/utils/run_algo.py", line 362, in _run overwrite_sim_params=False, File "/root/catalyst-venv/local/lib/python2.7/site-packages/catalyst/algorithm.py", line 749, in run self.analyze(daily_stats) File "/root/catalyst-venv/local/lib/python2.7/site-packages/catalyst/algorithm.py", line 490, in analyze self._analyze(self, perf) File "buy_and_hodl.py", line 83, in analyze ax1 = plt.subplot(611) File "/root/catalyst-venv/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 1052, in subplot fig = gcf() File "/root/catalyst-venv/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 588, in gcf return figure() File "/root/catalyst-venv/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 534, in figure **kwargs) File "/root/catalyst-venv/local/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 170, in new_figure_manager return cls.new_figure_manager_given_figure(num, fig) File "/root/catalyst-venv/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 1049, in new_figure_manager_given_figure window = Tk.Tk(className="matplotlib") File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1818, in init self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) _tkinter.TclError: no display name and no $DISPLAY environment variable

lacabra commented 7 years ago

Can either one of you confirm that you are running these commands in a local machine, vs ssh'ing remotely to another machine. If that's the case, this problem is covered elsewhere, for example: here

Alternatively, if you don't have a display, you can run matplotlib without an interactive display by saving plots to files for example, as explained here

Found this other relevant suggestion: export DISPLAY=0.0; xhost + from this post

Let me know if any of the above resolve your issue.

lacabra commented 7 years ago

One clarification note. Catalyst doesn't need matplotlib to run, it needs matplotlib to display summary/performance charts if you so choose. You can comment out all the code in the def analyze() function in your algo, and just specify an output file with the -o flag in the command line. You can then use other software to analyze the results, such as pyfolio.

rjoshig commented 7 years ago

I am using Windows Subsystem for Linux and logged in via ssh using Putty. I tried the ssh -X option . Still not working. Thanks for taking time to help us. I will try and figure out this display thing.

Question

  1. So I run this in command line with -o option

catalyst run -f buy_and_hodl.py --start 2017-3-2 --end 2017-7-31 --capital-base 100000 -o bah.pickle

  1. Then I started jupyter jupyter notebook

  2. I can see that .ipynb are generated. -rw-rw-r-- 1 ethdev ethdev 195688 Oct 19 19:29 Untitled.ipynb

  3. Is this file generated ? Can i specify the filename? if yes how?

  4. What exactly is bah.pickle in the command above? Is this the output of the run.

  5. Bascically how do i generate the ipynb file using the run.

lacabra commented 6 years ago

Closing this issue, since it's not specific to catalyst, but to the specific running environment and matplotlib. See my first post above for alternative setups.

@mesnia, please open different issues to report different problems, otherwise it's hard to keep track of them. But answering your question on number 3, inside jupyter notebook, go to File -> Rename. This will rename the current notebook, and use that for the filename to save it on disk.

the pickle is the output of the catalyst simulation that contains the performance data of your algorithm. The .ipynb is a copy of the jupyter network that you just created, which is the list of commands you have run, and the results from running these commands, so they are two very different files.

mautc12 commented 6 years ago

I have coding:

import matplotlib

matplotlib.use('Agg')

import matplotlib.pyplot as plt

print ('Hello, how are you now')

import numpy as np import matplotlib.pyplot as plt n = 1000 X = np.linspace(-np.pi, np.pi, 256, endpoint=True) C,S = np.cos(X), np.sin(X) plt.plot(X, C) plt.plot(X,S) plt.show() When I am running the above example in the server through the laptop windows connected to the server's ubuntu, the following error appears: image Please help me? I followed this link: https://stackoverflow.com/questions/37604289/tkinter-tclerror-no-display-name-and-no-display-environment-variable but failed thank you! I

nikithashr commented 6 years ago

Hi, could anyone find a fix for @mautc12 's problem

lacabra commented 6 years ago

As posted above, this issue is unrelated to Catalyst, and there are many different configurations that can cause and resolve this issue. First of all, we don't have enough information about @mautc12's environment to resolve this issue. Some possible troublehsooting that you would need to figure out before attempting to display any Catalyst output would be:

Once you have all of the above pieces installed, and working, you may need to tweak their configuration and test them using something as simple as opening an instance of xterm remotely and have it appear in your local environment. Once you have that, you can start tackling the Catalyst-specific errors, so as you can see this is mostly unrelated to Catalyst.

wentianl20 commented 6 years ago

@lacabra 's answer should solve this issue. You need a XQuartz or similar software on client and configure your server config with X11 Forwarding yes something.

rameshwarmore555 commented 5 years ago

@mautc12 i am also having the same issue can tou help me with that? thanks in advance

kaibawong commented 5 years ago

Hi, I am running python via binder and would like to run a GUI code. Having done from tkinter import *

I get the following error: (I am not sure what is wrong.. is it saying I dont have the correct environment?) Please help!

TclError Traceback (most recent call last)

in 21 22 # tkinter GUI ---> 23 root= tk.Tk() 24 25 canvas1 = tk.Canvas(root, width = 1200, height = 450) /srv/conda/envs/notebook/lib/python3.7/tkinter/__init__.py in __init__(self, screenName, baseName, className, useTk, sync, use) 2021 baseName = baseName + ext 2022 interactive = 0 -> 2023 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) 2024 if useTk: 2025 self._loadtk() TclError: no display name and no $DISPLAY environment variable
balee323 commented 4 years ago

I ran into the same issue and set this in my code.

import Tkinter
import sys
import os

if os.environ.get('DISPLAY','') == '':
    print('no display found. Using :0.0')
    os.environ.__setitem__('DISPLAY', ':0.0')

#create main window
master = Tkinter.Tk()
master.title("tester")
master.geometry("300x100")

#make a label for the window
label1 = Tkinter.Label(master, text='Hellooooo')
# Lay out label
label1.pack()

# Run forever!
master.mainloop()
srishkee commented 4 years ago

I ran into the same issue and set this in my code.

import Tkinter
import sys
import os

if os.environ.get('DISPLAY','') == '':
    print('no display found. Using :0.0')
    os.environ.__setitem__('DISPLAY', ':0.0')

#create main window
master = Tkinter.Tk()
master.title("tester")
master.geometry("300x100")

#make a label for the window
label1 = Tkinter.Label(master, text='Hellooooo')
# Lay out label
label1.pack()

# Run forever!
master.mainloop()

Thank you so much for posting this - worked for me! I downloaded Xming and set the display using the os.environ setitem() function and Xming was able to display my Tkinter application.

gzpmanish commented 4 years ago

If we used a windows OS then we need to install Xming server. Try to connect putty and change the setting of putty is ssh>x11>enable X11 forwarding

jasvinderchhabra commented 2 years ago

After setting

if os.environ.get('DISPLAY','') == '': print('no display found. Using :0.0') os.environ.setitem('DISPLAY', ':0.0')

I am getting below issue.

window=tkinter.Tk() File "/usr/lib64/python3.6/tkinter/init.py", line 2023, in init self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) _tkinter.TclError: couldn't connect to display ":0.0"

Can anyone help please I am running code in Linux

mautc12 commented 2 years ago

MauTC da nhan duoc mail, xin cam on!

jasvinderchhabra commented 2 years ago

After setting

if os.environ.get('DISPLAY','') == '': print('no display found. Using :0.0') os.environ.setitem('DISPLAY', ':0.0')

I am getting below issue.

window=tkinter.Tk() File "/usr/lib64/python3.6/tkinter/init.py", line 2023, in init self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) _tkinter.TclError: couldn't connect to display ":0.0"

Can anyone help please I am running code in Linux