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

标签 python python-2.7 ipython jupyter plotly

我在 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/

相关文章:

打开 VIM 自动缩进后,Python 解释器无法正确读取缩进

python - Sendkeys 函数出现问题

mysql - 安装 mysql python 时遇到问题,在 django 中找不到 mysqldb 模块

python - 运行 IPyhon.widgets 时没有名为 'ipywidgets' 的模块错误

python - 将循环打包到函数中以静音变量的Pythonic 方法?

c++ - 如何在 Python 中实现 C++ 类,由 C++ 调用?

python - 为什么 3D numpy 数组按原样打印(它们是如何排序的)?

python - 按下按钮时 Tkinter GUI : Adding new entry boxes using . grid()

python - spyder IDE 的 ipython 启动配置

python - 在前进到下一个单元之前,强制 matplotlib 在 IPython/Jupyter 笔记本单元中完全渲染绘图