I'm trying to follow along with the following YouTube tutorial:
https://www.youtube.com/watch?v=D35m2CdMhVs
I set up the environment through Anaconda and am using Jupyter to code. I imported pandas and plotly for the code and yet the iplot function is not recognized.
The import statements in the code look like this:
import plotly
import plotly.figure_factory as ff
import pandas as pd
This is the specific error message I'm getting:
NameError: name 'iplot' is not defined
The tutorial is from 2018 and the author specifies the versions of some of the dependencies at the beginning of the tutorial. According to this answer, there has been a change in plotly between v3 and v4. According to the official web site 4.0 came in 2019.
Please check for compatibility between what is in the tutorial and what the version of the API you're using offers. Also quite often people mix Python 2.x with 3.x (especially if they polute the environment set by Anaconda and similar with direct calls to pip/pip3).
Related
Qt5Agg is necessary to use the mayavi 3D visualization package. I have installed PyQt5 and mayavi using pip in a separate copied conda environment. The default backend then changes from TkAgg to QtAgg. This is a bit weird because in an earlier installation in a different PC the default changed directly to Qt5Agg. I always check the backend using the following commands from the python console :
import matplotlib
matplotlib.get_backend()
Even with the backend being 'QtAgg', I am able to use mayavi from the terminal without any issue but not when I do so in Pycharm. Here I get a non-responsive empty window (image below) :
Image of the non-responsive window
I have been able to get rid of this issue by explicitly using Qt5Agg instead of QtAgg before the plt call :
import matplotlib
matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt
But I would prefer a better way than using the above in every script that I write. As I had mentioned earlier, I already have mayavi installed and have used it successfully it in Pycharm in a different PC and there the default backend is 'Qt5Agg' and hence there is no need to change the backend explicitly.
Is there anything obvious that I'm overlooking ? Can you please let me know of a way to change the default backend for matplotlib from QtAgg to Qt5Agg after PyQt5 installation using pip ?
Thanks in advance !!
Thanks to #PaulH's comment, I was able to solve the issue. Owing to #mx0's suggestion, I shall now explicitly mention the fix below so that others can also benefit from it.
In a particular conda environment, if matplotlib package is installed, then there will be a 'matplotlibrc' file stored somewhere that defines what the default backend will be whenever matplotlib is imported from that conda environment. The location of this 'matplotlibrc' can be found using the following commands :
import matplotlib
matplotlib.matplotlib_fname()
Please look into the following link if there's any deprecation issue with the above commands :
https://matplotlib.org/stable/tutorials/introductory/customizing.html#customizing-with-matplotlibrc-files
Once the location of the 'matplotlibrc' file is known, open it and simply uncomment one line inside this file. Just change the backend from :
##backend: Agg
to :
backend: Qt5Agg
And that's it. All the plot window troubles in PyCharm will be solved as far as the mayavi 3D visualization package is concerned. For any other use, where a specific backend is necessary, you can also set the default to any other backend of choice.
I'm just started to search Aliexpress-API documentation. In there: Developers.aliexpress , Im coding in python and need to import AliexpressSolutionProductPostRequest from top.api but it fails.
I installed top lib on Windows like that: python -m pip install top
Reinstalled twice but it fails. Its official website and fails. I can't figure it out.
AttributeError: module 'top.api' has no attribute 'AliexpressSolutionProductPostRequest'
This library has diffrent functions for Alibaba , not for aliexpres. Any suggestion for fix that ? Actually i can't find top library's offical documentation too.Thank you..
Okey. I found this library for fix that error. We need to install aliexpress-sdk:
pip install aliexpress-sdk
or (for pre-release):
pip install git+https://github.com/bayborodin/aliexpress-sdk
Now I can import Aliexpress modules which are in Aliexpress API Documentation.
Example module import for aliexpress:
from aliexpress.api import AliexpressSolutionProductPostRequest
I just learned offical way to do that.
After create an app on Aliexpress Console, you can generate API SDK for Python. In there you can find top library's functions which are in Aliexpress API Documentation. So we need to create App first, once accepted , we can do all these stuff.
I'm following the PyViz tutorial found here: http://pyviz.org/tutorial/01_Workflow_Introduction.html, and I am running into an issue with displaying images side by side when using the exact code from the tutorial (in the New York vs Texas Measles example).
I should mention that I did not download the conda environment as outlined in the tutorial. I opened a new Jupyter Notebook, installed all the specified libraries(I hope), and downloaded the examples from the PyViz github page.
The libraries I downloaded/imported are the following:
import holoviews as hv
import bokeh
import matplotlib
import pandas as pd
import datashader
import dask
import geoviews
import numpy as np
import hvplot.pandas
import hvplot
import holoviews as hv
hv.extension('bokeh', 'matplotlib', width="100")
The part of the tutorial code that does not work is the following:
by_state["Texas"].relabel('Texas') + by_state["Florida"].relabel('Florida')
Both statements run on their own, but the plus sign does not appear to work. The error states:
TypeError: gridplot() got an unexpected keyword argument 'width'
The rest of the tutorial runs smoothly. Does anyone have any insight into what could be going wrong here?
Thank you!
I am trying to use Google Speech API to recognize speech from mic input in real time. I have tried https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/speech/cloud-client/transcribe_streaming_mic.py
but this error came out. Anybody knows how to solve this?
from google.cloud.speech import enums
ImportError: cannot import name 'enums'
Update:
I have solved the problem by running the code in virtual environment as suggested by the official Cloud Speech API website. However, I still dont understand why we need to run that in virtual environment instead of my original environment as the virtual environment is not Linux or other OS.
I am using cloud function to transcribe the audio to text.
I believe the documentation for google-cloud-speech has been updated, you may refer to the documentation. https://pypi.org/project/google-cloud-speech/. I believe the class is now called speech_v1, you can use the alias "as speech" to make the github sample codes work.
from google.cloud import speech_v1 as speech
from google.cloud.speech_v1 import enums
from google.cloud.speech_v1 import types
HTH.
I got mine working with the following import
from google.cloud.speech_v1.gapic import enums
Using pip install google.cloud.speech, you are getting the latest version, currently V2.
In V2, enums and types have been removed and are no longer needed.
https://github.com/googleapis/python-speech/blob/master/UPGRADING.md#enums-and-types
I locally use Bokeh server to visualize data. I tried doing this in Azure's version of Databricks as well, but couldn't get even the first lines of this simple example to run:
from bokeh.io import push_notebook, show, output_notebook
from bokeh.plotting import figure
output_notebook() # <- fails
This fails with the following error:
TypeError: publish_display_data() missing 1 required positional
argument: 'data'
I investigated further and found out that databricks is apparently built open IPython 2.2.0, which is over 4 years old!
import IPython
IPython.__version__ # Returns '2.2.0'
Is there anything I can do? Did anyone have success with running a bokeh server in Databricks? I want to have some kind of interactive Dashboard, and Databricks' own dashboard is extremely limited
As you note, IPython 2.2.0 is ancient. I'm not sure how far back you'd have to go in Bokeh releases to find one that supports it. The function publish_display_data is a Juypter/IPython API, and unfortunately it has seen a few breaking changes over the years. The Bokeh project used to maintain a compatibility polyfill for it to try to smooth over these changes, and support older versions, but it was removed in this commit last year:
https://github.com/bokeh/bokeh/commit/fb3f9cc4f9e9af786698462a9849e46c0ea34cf2
After that commit, 4.3 is the minimum notebook version for any use. Before that commit, some set of earlier Jupyter releases will work, but I can't say exactly how much earlier, and I can't guarantee that an emebedded Bokeh server apps would work (i.e. very possibly only inline standalone plots would work) Embedded Bokeh server apps have never been tested on anything earlier than Jupyter 4.3 and I would never make a claim that Bokeh supports embedded apps in notebook versions older than that.
TLDR; I highly doubt things are workable on IPython 2.2.0