can't import plotly libraries (Python) - python

I am having a bit of trouble getting my plotly imports to work. I am a new Python programmer.
I followed the following instructions to a 'T':
https://plot.ly/python/getting-started/
When I copied the demo code into pycharm, I got errors on the imports. So I found a guy who had the same question as me here:
Import error : No module named plotly.plotly
Following prompts in the comments, I used "pip show plotly" in my command line, and copied and pasted the path, and reformatted the import like so (again as prompted by comments and the accepted answer:
import sys
sys.path.insert(0, 'c:\users\wesle\appdata\local\programs\python\python36-32\lib\site-packages')
import plotly.plotly as py
Still getting the same red squigglies...
Is plotly the right library to be using for a beginner? I will be using it to plot the results of numerical methods like calculating function values using taylor series and linear algebra stuff. I don't need super fancy, just whatever is easiest to code. By the way, really digging Python coming from Java.

So, I'm not a command line expert and decided to look within my IDE for a tool to set up plotly, as I was not having success with the "pip" stuff. I am using PyCharm, and the following simple steps took care of my problems in less than 30 seconds.
Settings
Click Project: "MyProjectHere" in left hand nav menu
Select Project Interpreter from the above drop down
Find the green 'plus' sign near the upper right edge of the window
that comes up.
Type Plotly in the search bar
Click install.
Maybe one day I won't be a dumb monkey who doesn't know how to use a command line like all the cool kids, but for now this worked for me.

If you are using Anaconda Python for notebook, you have to manually install plotly in anaconda:
Open Anaconda navigator
Go to Environments
Change installed to not installed
Search packages field and type plotly as uninstalled
Select it and click apply
After it gets installed you'll be able to import the package in notebook.

Related

I am new to VSCode, Python, and the OpenAI API, and I am unable to figure out how to access the hover documentation

Every video I watch shows documentation when the user hovers over code, yet mine is nearly empty.
Example:
response = openai.Completion.create(engine="text-davinci-001", prompt=prompt, max_tokens=6)
If I hover over "create" it shows "create: Any" inside the pop-up window.
This is much less descriptive than what I see in tutorials.
How do I access documentation on a given object from within VSCode?
I have tried installing/reinstalling Python, IntelliCode and Docs View from inside VSCode.
IntelliCode does add links to GitHub but still no the standard documentation like I was expecting.
What you want is called Intellisense which is provided by extension Python and Pylance.
So the first step is to ensure that you have installed these two extensions.
Because the Intellisense is obtained from the description file in the package, and your code does not have the statement to import the package, I guess you did not install the package or import it. You have to use command pip install openai in the terminal and use the correct codes to get it:
import openai
response = openai.Completion.create(engine="text-davinci-001", prompt=prompt, max_tokens=6)

How do I import Pandas library into PyCharm?

I have downloaded Pandas library with pip install pandas through the command prompt, when I try to import pandas as pd PyCharm returns an error : ModuleNotFoundError: No module named 'pandas'
I have tried to uninstall and install again many times but nothing seems to work. Does anybody know a solution to this?
You can try downloading the library from PyCharm settings:
File -> Settings
then, Project: -> Python Interpreter
Click a + sign to the right,
Search for the pandas library,
and finally, press 'Install Package'
I think you have to choose the right python interpreter. Check my screenshot
You likely have multiple copies of Python installed on your system. PyCharm can be configured to use any version of Python on your system, including any virtual environments you've defined. The solution is to match up the version of Python you've installed Pandas into with the version of Python that PyCharm is using to run your code.
There are two places where you specify a Python version. First of all, your Project has a version associated with it. Check the "Python Interpreter" section of the "Project" section of your Preferences for that. That version is used for syntax highlighting, code completion, etc.
By default, the abovementioned Python version will also be used to run your code. But you can change the version of Python that your code is run with by creating or modifying a Run Configuration. To do this, check the menu next to the Run and Debug toolbar buttons near the top-left of your PyCharm window.
When you do get into the Python Interpreter section of the Preferences, you'll find that you can see all of the modules installed for each Python version that PyCharm knows about. You can use this to check to see if Pandas is installed for a particular Python version.
I would suggest you get comfortable with all that I've said above. It will save you many headaches in the future.

PyCharm on MAC - ModuleNotFoundError: No module named 'sklearn'

I'm using PyCharm and learning the basics of Machine Learning through a Mooc.
As always, things don't go as expected when you try things shown by the teacher by yourself and until now I was able to fix the issues by myself but I'm stuck since quite a while and that's why I created an account here :)
when I try import sklearn as pd (can't find how to do this as "code") I get ModuleNotFoundError: No module named 'sklearn'
I've had the same issue with pandas and numpy previously and was able to solve it by adding
import sys
sys.path.append("numpy_path/pandas_path")
and trying some things on the terminal (I'm on Mac) like pip install numpy or conda install numpy but this time nothing seems to work.
I suspect the issue to be that sklearn is somewhere else on my computer than where the Python program is searching but am not sure.. Let me know if you can help :)
It may be that Pycharm is using a different interpreter environment than you were using before. Best way to check is in Pycharm go to Pycharm on the menu, then preferences, then under 'Project' choose 'Project Interpreter'. At the top a dropdown will show you what environment Pycharm is using for this project. Underneath will be all the libraries you have installed in that environment. You can look down the list and check if the libraries you want are installed. If they aren't hit the + button underneath, search for the libraries, select and hit install.
Also a note. It's odd that you are choosing to import sklearn as pd as that is not the convention. The convention is to import pandas as pd. Technically it is not incorrect, the interpreter will accept it, but it is not the convention.

Import error : No module named plotly.plotly

I am working on project and getting this error
ImportError: No module named plotly.plotly
I tried:
pip install plotly
pip install --upgrade plotly
But import plotly.plotly as py didn't work.
Not sure if pyzo and python modules are stored at different location on your computer. And how they are referred.
But you can try following to give absolute path name for plotly while loading module and see if it works.
import sys
sys.path.insert(0, 'c:\\pyzo2015a\\lib\\site-packages\\plotly')
import plotly.plotly as py
I had the same exact problem, but the current answer did not resolve my issues. If that's the case, here is an alternative (IDE dependent):
I was not having success with the "pip" stuff. I am using PyCharm, and the following simple steps took care of my problems in less than 30 seconds.
Settings
Click Project: "MyProjectHere" in left hand nav menu
Select Project Interpreter from the above drop down
Find the green 'plus' sign near the upper right edge of the window
that comes up.
Type Plotly in the search bar
Click install.
Maybe one day I won't be a dumb monkey who doesn't know how to use a command line like all the cool kids, but for now this worked for me.
I had the same problem installing plotly with pip and then import not being able to find it, but it worked when I used conda, instead.

Need help getting VPython to work on Atom

Recently started using the code editor Atom for my Python code. I've been able to get pretty much everything I need to work, except VPython. I've been told that VPython is supported/compatible with Atom, yet it doesn't work.
The main issue is that I'm unable to import the 'visual' module. I've even tried suggested alternatives such as importing 'VPython' or 'vis', and even uninstalled/reinstalled VPython several times in different ways.
Any advice would be highly appreciated.
Check out the Hydrogen package in Atom:
https://atom.io/packages/Hydrogen
Run code and get results inline using Jupyter kernels like IPython, IJulia, and iTorch. It's one of the coolest packages in Atom as it supports inline plot visualizations if that's what you're looking for.
I hope this helps.
The visual module is part of "classic vpython" which only runs on python 2.7 . If you are using python 3.5.3 or higher then you will need the new VPython 7.x package which is probably what you installed if you followed the instructions at vpython.org . Try running this two lines vpython code.
from vpython import *
box()
If you run these two lines of code you should see a 3D box appear in a webgl canvas in your webbrowser. To write a vpython program use the new syntax and not the old "classic vpython" syntax.
http://www.glowscript.org/docs/VPythonDocs/index.html

Categories

Resources