I've been running into this same issue no matter what I do. I'm running Python on Spyder (custom python 3.7.9) and I keep getting errors when importing packages.
from pandas import dataframe
from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import MinMaxScaler
The above are the modules in question which won't import. The errors I'm getting are:
ImportError: cannot import name 'dataframe' from 'pandas' (C:\Users\name\AppData\Local\Programs\Spyder\pkgs\pandas\__init__.py)
&
File "<ipython-input-8-4c3b6a7a4279>", line 1, in <module>
from sklearn.preprocessing import LabelEncoder
ModuleNotFoundError: No module named 'sklearn'
Using pip install <some package> doesn't seem to work either, even after resarting my Kernal. I tried to uninstall and reinstall and that doesn't work. Other modules in the ``pandaspackage import for me. Nothing fromsklearnseems to import. I even sepcified the exact location of the package inPYTHONPATH Managerand it still won't importsklearnandpandasdoesn't seem to have thedataframe``` module file included. I'm not sure how to ensure I get everything I need installed and imported.
EDIT: fixed the simple typo of dataframe instead of DataFrame. The main issue is now sklearn which has given me consistent issues across multiple scripts. setup.py method doesn't work, just keeps giving me the error that sklearn isn't found when trying to run the setup.
You must install miniconda if you are not using Spyder in Anaconda. You can then find out how to set this environment here: https://docs.spyder-ide.org/5/faq.html#using-packages-installer
You can install packages using conda install <some package> after setting the environment to the miniconda environment.
Related
I am using Anaconda to manage my environments, and I have a strange problem with netCDF4.
I have several Jupyter notebooks in my environment that I've been using with netCDF4, no problem at all. I'm only interested in reading NetCDF files, so I'm only really using the Dataset.
Now I'm implementing the algorithm from my Jupyter notebooks in a Python package, and I get this error (in VS Code):
No name 'Dataset' in module 'netCDF4'
I can see that it's installed in Anaconda Navigator and if I try to do a pip install it reports that netcdf4 is already installed and all dependencies are met.
I've read similar-sounding posts here and they do not solve my problem.
In response to a comment, the error is where I import Dataset:
from netCDF4 import Dataset
This also gives the error:
import netCDF4 as nc
salinity_data = nc.Dataset(<file name etc...>)
The code completion does not show anything in the netCDF4 package other than some "_" prefixed variables.
I'm using Python 3.8.12 and I am using the correct virtual environment that I set up with Anaconda.
The error message is coming from pylint, not the Python interpreter (see comments above).
The code will run fine, so the issue is with pylint and the configuration. I can suppress the error by:
from netCDF4 import Dataset #pylint: disable=no-name-in-module
This will do for now, but at some point, I'd like to figure out why pylint is reporting this.
I have also found a package that works better for what I want to do wth the netCDF files:
https://github.com/h5netcdf/h5netcdf
This doesn't have all the hidden dependencies that netCDF4 does, and has a "legacyapi" that is a drop-in replacement for the netcdf package:
import hfnetcdf.legacyapi as nc
my_data = nc.Dataset('my_data_file.nc', 'r')
not very proficient yet in python and i'm trying to run :
import pyfolio as pf
pf.create_full_tear_sheet(portfolio.mean(axis=1))
(reference in the end of: https://blog.quantinsti.com/xgboost-python/)
in Anaconda/Spyder but get the
ModuleNotFoundError: No module named 'pandas.plotting._timeseries'
checked that pyfolio is installed and googled the error but didn't come across any solutions.
Would really appreciate some help.
tx!
It seems the pandas.plotting._timeseries module is only available for pandas versions before 0.25.x.
You can see the _timeseries module is present in 0.24.x
and is removed in 0.25.x (looks like the API changed to pandas.plotting._matplotlib.timeseries).
If you install an older version of pandas (anything before 0.25.x), it should work. Here's an example for last 0.24.x release:
pip install pandas==0.24.2
A script I'm running is failing at one of my imports, and I can't figure out why.
The offending line of code is:
from pandas.compat import lzip
Error message: ImportError: cannot import name 'lzip'
This script is being run in a conda virtual environment, with dependencies installed through conda. Specific to this case, I have pandas and pandas-compat installed, also through conda, and running on Python3.6. (3.6 because 3.7 is incompatible with pandas-compat in an earlier attempt on a python3.7 env)
Help please, or point to where I may find the solution?
Not sure why lzip wouldn't be available, save for the warning at the top of the pandas API reference docu (Warning The pandas.core, pandas.compat, and pandas.util top-level modules are PRIVATE. Stable functionality in such modules is not guaranteed.). The first solution on this page didn't work for me.
Current pandas version: 0.25.3
Current pandas-compat: 0.1.1
Current python: 3.6.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.
I have the newest Anaconda 2.3 on a non-network-Linux-machine. Everything works fine besides
import sklearn
I then get back
----> 1 import sklearn
sklearn.py in <module>()
ValueError: Attempted relative import in non-package
I have to go into the /pkgs folder in anaconda and into scikit-learn to import from there. This works and whats even weirder, when I type
import
and the tabulator to show possible packages, sklearn is shown.
Might be that you're using another Python installation on your computer.
For instance, I have Python in my Anaconda environement and the other one by default. If execute: ~/anaconda/bin/python I can import sklearn without problems.
On the contrary if I execute /usr/bin/python and then try to export it I get the error message since I installed sklearn from Anaconda.
Check your PATH variable with typing $PATH on your terminal and check the order, if Anaconda is not the first one (or it's not there) type: export PATH="/path/to/anaconda/bin:$PATH"
I hope this works.