gpt4 book ai didi

python - 将 plot.ly 用于 Python 时,Module_six_moves_urllib_parse 对象没有属性 urlparse

转载 作者:行者123 更新时间:2023-11-28 18:33:09 25 4
gpt4 key购买 nike

我在 Jupyter 中运行以下代码:

import plotly.plotly as py
import plotly.graph_objs as go

# Create random data with numpy
import numpy as np

N = 100
random_x = np.linspace(0, 1, N)
random_y0 = np.random.randn(N)+5
random_y1 = np.random.randn(N)
random_y2 = np.random.randn(N)-5

# Create traces
trace0 = go.Scatter(
x = random_x,
y = random_y0,
mode = 'markers',
name = 'markers'
)
trace1 = go.Scatter(
x = random_x,
y = random_y1,
mode = 'lines+markers',
name = 'lines+markers'
)
trace2 = go.Scatter(
x = random_x,
y = random_y2,
mode = 'lines',
name = 'lines'
)
data = [trace0, trace1, trace2]

# Plot and embed in ipython notebook!
py.iplot(data, filename='scatter-mode')

我得到的错误结果是:

/Library/Python/2.7/site-packages/requests/packages/urllib3/util/ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning. SNIMissingWarning /Library/Python/2.7/site-packages/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning /Library/Python/2.7/site-packages/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning:

A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.

--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) in () 34 35 # Plot and embed in ipython notebook! ---> 36 py.iplot(data, filename='scatter-mode')

/Library/Python/2.7/site-packages/plotly/plotly/plotly.pyc in iplot(figure_or_data, **plot_options) 173 embed_options['height'] = str(embed_options['height']) + 'px' 174 --> 175 return tools.embed(url, **embed_options) 176 177

/Library/Python/2.7/site-packages/plotly/tools.pyc in embed(file_owner_or_url, file_id, width, height) 407 else: 408 url = file_owner_or_url --> 409 return PlotlyDisplay(url, width, height) 410 else: 411 if (get_config_defaults()['plotly_domain']

/Library/Python/2.7/site-packages/plotly/tools.pyc in init(self, url, width, height) 1382 def init(self, url, width, height): 1383 self.resource = url -> 1384 self.embed_code = get_embed(url, width=width, height=height) 1385 super(PlotlyDisplay, self).init(data=self.embed_code) 1386

/Library/Python/2.7/site-packages/plotly/tools.pyc in get_embed(file_owner_or_url, file_id, width, height) 313 "\nRun help on this function for more information." 314 "".format(url, plotly_rest_url)) --> 315 urlsplit = six.moves.urllib.parse.urlparse(url) 316 file_owner = urlsplit.path.split('/')[1].split('~')[1] 317 file_id = urlsplit.path.split('/')[2]

AttributeError: 'Module_six_moves_urllib_parse' object has no attribute 'urlparse'

我已尝试通过此线程修复它

Attribute Error trying to run Gmail API quickstart in Python

  1. 我执行了 export PYTHONPATH=/Library/Python/2.7/site-packages 并确保我首先将其取消设置为空白(是的,该路径存在于我的 Mac 上)。

  2. 我更新了 w3lib (1.13.0)six (1.10.0)

  3. Jupyter 4.0.6 和 Python 2.7.6

还有什么可能出错?请帮忙。

最佳答案

我意识到我在 Jupyter 中选择了错误的内核。所以如果它是 PySpark 内核,它会给我错误。如果我使用 Python2 或 Python3 内核,那没问题。

关于python - 将 plot.ly 用于 Python 时,Module_six_moves_urllib_parse 对象没有属性 urlparse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35033473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com