RemarkableUnion1080 · 2022-01-24 12:52
So i was dabbling in using emacs as a python ide and as i was trying to execute a script i noticed a strange error.
When i try to use pandas it does not recognize any pd functions (eg pd.read\_csv) , it does let me use matplotlib, sklearn etc. When i try it within emacs python shell it works, as well as in the regular terminal (writing it in vim then executing the code). Any and all help would be really appreciated.
The error message: AttributeError: module 'pandas' has no attribute 'read\_csv'
gmoutso · 2022-01-24 14:02
Check
pd.__file__
pd.__version__
in both Emacs python shell and your terminal, to make sure you are using the same module.
RemarkableUnion1080 · 2022-01-24 17:15
thanks for your response.
in emacs: pd.\_\_file\_\_ : returns the file im currently writing (do not really understand this)
pd.\_\_version\_\_ : module pandas has no attribute '\_\_version\_\_'
In terminal: pd.\_\_file\_\_ : finds the file on the system
pd.\_\_version\_\_ : 1.4.0
What should i do with this information, thanks a lot!
gmoutso · 2022-01-24 17:32
It should not be the file you are using. Wild guess, is your file called pandas.py? If so, this should be it. Do you import pandas as pd? Is there any other file called pandas.py in your work directory? Next check is to compare
import sys; sys.path
RemarkableUnion1080 · 2022-01-24 17:37
The python script is called emacs.py, there is pandas.org which was created after the problem started. Yes pandas was imported as pd. When i try yhe sys.path in the script in ignores it
gmoutso · 2022-01-24 17:49
The issue is running a script, right? The connection with Emacs is that you wrote the script in Emacs, but after that how do you run the script via emacs? Is it on a command line? Would writing the same script then in any other text editor not give the same error? What about pandas.org? Does it have python code inside (in which case org tangle might produce pandas.py)? How was pandas.org created? I think a good troubleshooting is why does `pd.__file__` give your file? Especially if your file is not called pandas.py.
[deleted] · 2022-01-24 17:51
[deleted]
gmoutso · 2022-01-24 17:54
Try `print(sys.path)` but first, can you paste the exact full path name of `pd.__file__` that is the file you are writing?
gmoutso · 2022-01-24 18:21
Also, how do you run the script if from within Emacs? Does it run ok from the command line?
Shhhh_Peaceful · 2022-01-24 21:21
Do you have multiple versions of Python installed? For example, system Python and Anaconda?
Do you use macOS?
I'm asking because I use macOS and I have to use conda-mode (I think?) and set PATH inside my init.el to get Emacs to properly recognize my Python environment, otherwise it defaults to the system-wide Python install.
noexu · 2022-01-25 08:24
Config anaconda environment correctly and activate it in emacs by using conda-mode.
Shhhh_Peaceful · 2022-01-25 08:25
Yes, this is what I do.