Python script imports wrong pandas version - python

I´m running a python script on my Raspberry Pi 4 which imports pandas.
When I check the pandas version inside the script with
import pandas as pd
pd.show_versions()
And run the script with:
python3 myscript.py
The output is:
INSTALLED VERSIONS
------------------
python: 3.7.3.final.0
pandas: 0.23.3
numpy: 1.21.6
But when I use the console and check the pandas version by pip
pip3 list
The output is:
Package Version
------------------ -----------
numpy 1.23.5
pandas 1.5.2
Why does pip3 shows a different version then python3 and how can I force to use the "right" version? I´m not using any virtual environments.
Side fact:
Have the same issue with pip itself. Calling it inside the script returns 18.1 and checking on conole returns 22.3.1

Instead of
import pandas as pd
print(pd.__version__)
Can you please try the below method?
import pkg_resources
pkg_resources.require("pandas==1.5.2")
import pandas as pd
print(pd.__version__)
pkgs are installed, we can use the above method to get to the desired version.
 
Since I do not have enough reputation, I am unable to keep comments :(

Related

Python Deprecation warning

DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working.
These are my import statements.
import pandas as pd
import numpy as np
import os
import pymssql
os.getcwd
os.chdir('D:\Sushil\Output')
How can we fix this, since I am running spyder IDE for development connecting to sql server.
Looks like you are using older versions of python packages. Please update these packages using the following commands in cmd.
pip install --upgrade pymssql
pip install --upgrade pandas
pip install --upgrade numpy
Yes the warning message was regards pymssql. I have upgraded to the newer version. It is working. No more warning message now.

i have done "!pip install pandas" but Jupyter still dont find it

i first use jupyter notebook.
i tried to run
import pandas as pd
but it returns
No module called pandas
i've tried
!pip install pandas
it run successlfully
jupyter show installing process
but after pandas installed, it still return
No module called pandas
when i run
import pandas as pd
why ? and how to fix it
You probably have multiple pythons installed. See instructions here

Two versions of Pandas causing problems

It appears that when I run >conda list, I have two versions of pandas installed.
pandas 0.23.4 py36h830ac7b_0
pandas 0.22.0 <pip>
I cannot run import pandas or import pandas as pd in my console (Anaconda - Spyder/Jupyter Notebook) to check the version, but I am getting errors thrown in a script related to pandas:
Traceback (most recent call last) ...
from pandas.errors import
AbstractMethodError
ImportError: cannot import name 'AbstractMethodError'
I was going to do >conda update pandas but it said that my numpy would be downgraded. That doesn't sound right! How do I fix this?
It will be hard for someone on SO to debug your exact issue: The fastest way to fix your particular problem is most likely a fresh install of Anaconda. Then to set up a conda environment in your fresh install.
See the following:
Conda Environments: Creating an Environment
Powershell users will need this fix
This will avoid any conflicts with other python versions or pip
This will also allow you to maintain different environments with different versions of numpy or pandas
See below for an example of how simple this is to switch between 2.7 and 3.6
[py27] PS C:\Users\me> python --version
Python 2.7.15 :: Anaconda, Inc.
[py27] PS C:\Users\me> deactivate
Deactivating environment "py27..."
PS C:\Users\me> activate deeplearning
Activating environment "deeplearning..."
[deeplearning] PS C:\Users\me> python --version
Python 3.6.5 :: Anaconda custom (64-bit)

Can't import numpy in python 2.7

When running the following code in python 2.7:
import numpy
I get the result:
ImportError: No module named numpy
I have however got numpy installed for python 2.7, which is seen when running the following in terminal:
pip install numpy
I get the following:
Requirement already satisfied: numpy in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Working on macOS10.13.1
What am I missing?
Any help will be greatly appreciated!
have you tried uninstalling the numpy package and re-installing it? As mentioned you may be running python 3 instead of python 2 which could cause this issue.alternatively you could install an api like anaconda which comes with numpy pre-installed this may resolve the missing module. anaconda website: https://www.anaconda.com/download/

Anaconda and package installation (pydicom)

I have the following problem.
I have tried to install the pydicom package in python 2.7 using the following command (windows, anaconda setup):
conda install -c conda-forge pydicom
everything seems to work fine, the package seems to be installed.
I type
conda list
and in the list I see
pydicom 0.9.8 <pip>
I open spyder, or pycharm, type
import pydicom
and I get
ImportError: No module named pydicom
I have no idea what am I doing wrong. I went through http://conda.pydata.org/docs/using/pkgs.html and everything seems to be fine.
Please assist.
Since you are using 0.9.8, you actually need import dicom rather than import pydicom.
Due to this confusion, it will be import pydicom in version 1.0.0 and later.
I suggest you either update Python Version > 3.0, so that the output for conda list shows something like this:
(pip install pydicom)
pydicom 1.0.2 <pip>
python 3.6.4 h6538335_1
Now import using:
import pydicom #Preferable
==========================================================
Or install dicom instead of pydicom using:
(pip install pydicom-0.9.8)
pydicom 0.9.8 <pip>
python 2.7.0 h6538335_1
And then, import using:
import dicom
However, I strongly suggest that you install pydicom instead of dicom, since it is the upgraded version.

Categories