Whenever i am trying to import statsmodels.formula.api as smf i get the following error.
import statsmodels.formula.api as smf
Traceback (most recent call last):
File "<ipython-input-257-268d740a5877>", line 1, in <module>
import statsmodels.formula.api as smf
File "C:\Users\ldresl\Anaconda3\lib\site-
packages\statsmodels\formula\__init__.py", line 1, in <module>
from statsmodels import PytestTester
ImportError: cannot import name 'PytestTester'
You will have to update the package pytest and restart your kernel:
pip install pytest --upgrade
I had this problem importing statsmodels in a Jupyter notebook (Anaconda distribution). If you run on the same set-up, you can update a package in Anaconda like so:
conda update pytest
Do not forget to restart the kernel in the top navigation of your notebook afterwards. Hope that helps.
Worked for me,
pip install statsmodels --upgrade
pip install pytest --upgrade
Restart Kernel
Related
I am new to Python and I am trying to run a linear regression Python code, which I have downloaded.
My problem starts here
import pandas as pd
When I run the code, it tells me
Traceback (most recent call last):
File "E:\MACHINE LEARNING\linear regression tutorial\free_python_tips-main\free_python_tips-main\04_linear_regression\04_linear_regression.py", line 9, in <module>
import pandas as pd
ModuleNotFoundError: No module named 'pandas'
although this package is installed, in Anaconda as well.
How could I solve this?
go to your command prompt and type
pip install pandas
or if you are using anaconda then type
conda install pandas
you can refer these links for more details:
package installation with anaconda and
pandas documentation
and if you wanted to use Linear Regression then you need to install scikit learn
for pip
pip install -U scikit-learn
for anaconda
conda install -c conda-forge scikit-learn
then you need to import it in your code
from sklearn.linear_model import LinearRegression
Hope it solves your issue !!
I have technically already installed pandas-profiling using
pip install pandas-profiling
But when I try to import it, I get the following error:
import numpy as np
import pandas as pd
import pandas_profiling
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-e1a23f2a6f04> in <module>()
1 import numpy as np
2 import pandas as pd
3 import pandas_profiling
ModuleNotFoundError: No module named 'pandas_profiling'
First Error Image
So I tried installing it in Jupyter Notebook and got the following error as well:
import sys
!{sys.executable} -m pip install pandas-profiling
Collecting pandas-profiling
Could not find a version that satisfies the requirement pandas-profiling
(from versions: )
No matching distribution found for pandas-profiling
Second Error Image
I am also unable to install it using conda for both as I am unable to establish a connection to conda.anaconda.org for some reason.
To others who are looking to resolve this issue try these alternate steps :
Run pip install pandas-profiling command in a separate cell in the jupyter notebook.
After this just restart the kernal and run again. This should definitely work. Worked for me.
Based on the comments I was able to figure out the issue. I had to install jupyter notebook outside of the Anaconda root env and open it from the terminal.
pip3 install jupyter notebook
Once I did that it imported properly.
Steps:
Download the ZIP
Open Anaconda Prompt and go to the directory and extract the files to a folder
cd
C:\Users\farah\Downloads\pandas-profiling-master\pandas-profiling-master
Then type python setup.py install
Now you can use:
import pandas_profiling as pp
df = pd.read_csv('1234.csv')
pp.ProfileReport(df)
Reference: Pandas profiling
!pip install pandas_profiling # Run this from Jupytor notebook Ignore the warnings if any
from pandas_profiling import ProfileReport #restart the kernel if throws error
ProfileReport(df)
Note: This worked for me on Windows 10
From Anaconda Prompt:
conda install -c conda-forge pandas-profiling
I have a silly question. I'm working on Pyhton using the Intellij IDE. I'm trying to import the below:
from sklearn.preprocessing import Imputer
However, I receive the following error:
Traceback (most recent call last): from sklearn.preprocessing import
Imputer
Can you please help with this?
Solution is to use the latest version of scikit-learn library. Install it by using the following command (sometimes sudo is required before pip):
pip (or, pip3) install scikit-learn==0.19.1
the = symbol must be replaced by ==
Importing scipy in iPython gave me:
In [1]: import scipy
-----------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-4dc45f4c0083> in <module>()
----> 1 import scipy
/usr/local/lib/python2.7/site-packages/scipy/__init__.py in <module>()
/usr/local/lib/python2.7/site-packages/scipy/_lib/_ccallback.py in <module>()
ImportError: cannot import name _ccallback_c
In [2]:
Did a complete update of all the files of Anaconda
> conda update --all
and the error remains. Did a complete search on the web and there are similar problems but without solutions. Can you help me?
i am giving you two solutions which might work by my expereince
1. create a virtualenv and install the scipy package in that virtualenv and give path like this
import sys
sys.path.append('/home/shashi/.virtualenvs/venv/lib/python2.7/site-packages/')
import scipy
2.
Download the source code https://github.com/scipy/scipy/archive/v0.18.0-1.zipand unpack it. Open a command window in the folder where the setup.py of the module is located and type
scipy python setup.py install
It looks like scipy is not installed
conda install -c anaconda scipy
Try this and let us know if you receive the error again
Cheers!
I tried to run from sklearn.datasets import load_breast_cancer on my iPython notebook (Python 2, Jupyter, Dato), and got the importError:
ImportError Traceback (most recent call last)
<ipython-input-12-09d44d891711> in <module>()
----> 1 from sklearn.datasets import load_breast_cancer
ImportError: cannot import name load_breast_cancer
But it works fine if I run others, e.g. from sklearn.datasets import load_diabetes, from sklearn.datasets import load_boston.
So how to import the load_breast_cancer? Thank you.
try pip install --upgrade sklearn
if you don't know where your kernel is running (if updating your machine didn't work, it seems like it is hosted somewhere else), run !pip install --upgrade sklearn in a notebook cell.