我正在使用macOS Mojave并尝试运行以下命令:
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch import optim
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from pyvirtualdisplay import Display
from IPython import display as ipythondisplay
from IPython.display import clear_output
from pathlib import Path
import random, os.path, math, glob, csv, base64, itertools, sys
import gym
from gym.wrappers import Monitor
from pprint import pprint
# The following code is will be used to visualize the environments.
def show_video(directory):
html = []
for mp4 in Path(directory).glob("*.mp4"):
video_b64 = base64.b64encode(mp4.read_bytes())
html.append('''<video alt="{}" autoplay
loop controls style="height: 400px;">
<source src="data:video/mp4;base64,{}" type="video/mp4" />
</video>'''.format(mp4, video_b64.decode('ascii')))
ipythondisplay.display(ipythondisplay.HTML(data="<br>".join(html)))
display = Display(visible=0, size=(1400, 900))
display.start();
但是当我尝试运行以上命令时,出现以下错误:
---------------------------------------------------------------------------
XStartTimeoutError Traceback (most recent call last)
<ipython-input-1-73a977c6bd7e> in <module>
31
32 display = Display(visible=0, size=(1400, 900))
---> 33 display.start();
34
35 def make_seed(seed):
/usr/local/lib/python3.7/site-packages/pyvirtualdisplay/abstractdisplay.py in start(self)
166 if not ok:
167 msg = 'Failed to start X on display "%s" (xdpyinfo check failed).'
--> 168 raise XStartTimeoutError(msg % d)
169 return self
170
XStartTimeoutError: Failed to start X on display ":1001" (xdpyinfo check failed).
我得到的唯一接近的东西是Why am I getting this message from xauth: “timeout in locking authority file /home//.Xauthority”?
这不是我在这里真正面对的。如何解决此问题?
我有同样的问题。然后我安装并开始XQuartz,此问题已解决。