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

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.

Related

ImportError: cannot import name 'Random' from 'django.db.models.functions'

Well, I am trying to run my django project in new environment, I installed all of my requirements although every package is installed but it is still giving me below mentioned error. I am not sure but I am guessing it is due to version conflict of some modules.
I looked for existing solutions or someone who faced similar situation but no success.
the Random method is located in django/db/models/functions/math.py . change your import statement to this :
from django.db.models.functions.math import Random

Python - Can't Get Pandas and Numpy Working in Visual Studio Code or Eclipse

I'm fairly new to IDE's and I'm trying to take courses in Python. No matter what I try, I cannot successfully run a python script that has import pandas and import numpy in it in either Visual Studio Code or Eclipse (running on Windows 10). I have Python 3.8 installed, and when I try running those commands in the shell it works fine. I suspect when I try executing an actual Python script instead of using the console, it might be using a different interpreter, and I only get errors when I try doing this, saying numpy is not defined. I also get the error "cannot import name 'numpy' from partially initialized module 'pandas' (most likely due to a circular import)" when I specify "from pandas import numpy" rather than "from pandas import *".
I am very frustrated and don't know how to fix this problem. I've tried searching for help but not having a programming background, I don't know where to go to resolve this or how.
I also cannot get pip or pip3 to work at all to install packages. Those commands don't get recognized.
Please help!
I recommend using Jupyter Notebooks/pycharm(IDE). Both are very useful for learning python and working with data, data manipulation, and data visualizations.
PyCharm knows everything about your code. Rely on it for intelligent code completion, on-the-fly error checking and quick-fixes & easy project navigation.
While
Jupyter Notebooks can run line by line, rerun specific lines after making changes, and it's inline output is very useful for debugging and visualizations. You can get it from https://jupyter.org.
Zepellin Notebooks can also serve as alternatives.

matplotlib.pyplot giving error 'ImportError: No module named Tkinter' on python 2.7

I'm using a remote machine for computation and data analysis. I don't have sudo access in this machine, for data analysis purposes I want to use python libraries such as vtk etc since pip is not installed in this machine, I set up a 'virtual-environment' and install VTK there,
I used the method explained here (https://stackoverflow.com/a/13958308/10755782). Then I could install vtk in the virtual environment using pip.
But now the problem is that I can't import matplotlib.pyplot, it is giving me the error
ImportError: No module named Tkinter.
This error is strange because matplotlib.pyplot works in this particular system outside my virtual-environment. There are a few workarounds to start using matplotlib.pyplot without tkinter such as this (https://stackoverflow.com/a/49988926/10755782), but this is not helpfull in my case as this machine is remote-accessed and I need 'tkinter' to view the graphs on my screen.
I tried installing 'tkinter' inside my virtual-env, but I could not ( since we can't install 'tkinter' with pip and I don't have sudo access).
As I could not find any immediate solution to this problem anywhere I tried to fix this myself and I did the following,
inside my virtual environment, the version of matplotlib was 2.2.4 and outside it was 1.2.0 ( which is working fine). So I downgraded the version of matplotlib inside my virtual environment to 1.2.0
pip install 'matplotlib==1.2.0' --force-reinstall
now I have the same version of matplotlib inside and outside the virtual env. But now, when I try import matplotlilb.pyplot as plt I'm getting the error
ImportError: /b/home/ipcms/rcheenik/Python_virt-env/python2.7/my_new_env/lib/python2.7/site-
packages/matplotlib/_cntr.so: undefined symbol: _intel_fast_memset
Is there any way to fix this ^^ error? any of these following will be able to help me.
without OR is there any way to install tkinter without sudo ? or inside the 'virtual-environment' ?
OR is there any alternatives to matplotlib.pyplot which works without 'tkinter' and still display graphs remotely? ( not favourable, as I have to rewrite the entire code )
Thanks in advance for the help.
I found this answer to a similar question however, which I believe would solve your issue.
https://stackoverflow.com/a/49988926/8775307
It imports matplotlib.pyplot without tkinter. I don't know if all the features are actually included though, so you'll have to test and let us know :).
You could always write to the administrator and request Tkinter - it's a widely used and useful package, so they might be willing to include it.

can't import plotly libraries (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.

python newbie: importing numpy module in eclipse

I'm trying to run a simple python program in eclipse. This is the first time that I'm importting any module.
So I downloaded: numpy and pylab (I'm using a mac) restarted my eclipse and the red line below the
import numpy
import pylab
disappeared so I understood that the reference to that module is ok.
Problem is that I still see red line below the code and wonder why? I have to stress out that I believe numpy was already 'pre-installed' I just upgraded the version (using 1.5.1-py2.7).
Can anyone tell what should I do to run this code?
my interpreter setting on eclipse:
If you are using PyDev, you should first have to go to Preferences, then Pydev, then Interpreter Python and then Libraries to add NumPy.
Else, verify that you have NumPy installed, from the interpreter, just call from numpy import *
Edit:
Also check you already have Matplotlib installed, the error you are getting on the console points to that being the cause, you can download Matplotlib here.
I recently installed Anaconda3 and just started learning how to use Pandas and I wanted to be able to work with Pandas in Eclipse as well.
I first tried adding a reference to the site-libraries at:
C:\Anaconda3\Lib\site-packages
And it seemed to work by allowing me to import numpy and pandas. However, since I had just used conda to update everything, my Python34 interpreter seemed to fail when I tried running some code and numpy was looking for my Python35 installation. For some reason this was located at:
C:\Users\myname\AppData\Local\Programs\Python\Python35-32
However, Anacondas installed another version somewhere else. By going into:
Windows > Preferences > PyDev > Interpreters > Python Interpreter
and clicking on Quick Auto-Config it found my Anacondas version of Python35 and then I just had to figure out how to make my current project use the Python35 interpreter.
Hint: To do this, you need to go into the Project properties by opening the project and choosing File > Properties or right-click the project to choose Properties.
Simply removed the old numpy and installed version 6. located here
Another way to circumvent this problem is to use pip install numpy check how to install pip

Categories

Resources