Pandas is not working, even after I installed it - python

I currently need to use pandas with Thonny, because pandas is installed locally there, but all my coding is in visual studio and i want to be able to use pandas in the editor i like. I have this error while trying to run a code for pandas.
No module named 'pandas'
File "/Users/myname/Desktop/Ambassador.py", line 1, in <module>
import pandas as pd
Even tho i have already installed it, i've made several attempts with pip, conda, i installed wheel and everything suggested.
Anyone knows why is this ?
for additional info i have a Mac

Check python version where pandas is installed and use same version to run your code

It could be cause you have installed pandas at the different virtual environment. I guess, you should try to check and change environment (⇧⌘P) in visual studio especially if you are using things like conda.
Also, check it for info about environments: https://code.visualstudio.com/docs/python/environments

Related

Pandas import module missing in VSCode

I am having issues with importing the pandas library into my project on VS Code. I have pandas installed on my machine and my machine is currently running python 3.9.12. I tried changing the interpreter in my IDE from 3.10.64 to 3.9.12 but I cannot find the path to it. I was wondering if there was anything else I should try/do to help fix this issue. Thank you!
Make sure you set the path using your environment variables as shown here
Then, using pip, just simply do !pip install pandas in order to have the pandas path set correctly automatically. I understand you may have installed it manually but this may help.

ModuleNotFoundError: No module named 'selenium'. How to fix it from Visual Studio Code?

I don't know about virtual environments and what they do, but all I wanted was to start learning this tutorial on python: https://www.youtube.com/watch?v=Xjv1sY630Uc&list=PLzMcBGfZo4-n40rB1XaJ0ak1bemvlqumQ
I did everything possible:
pip install selenium
pip3 install selenium
installed and uninstalled it
Added it in my environmental variables in the path. Like this:
Now what am I supposed to do? In Visual Studio Code I'm still getting this error no matter what I do and how many times I install, uninstall and add it to my environmental variables:
You can try importing the path to the file at the beginning of the file.
for example
import sys
sys.path.append(r'c:\workspace\pythontest\.venv\lib\site-packages')
Hope it helps you.

Unable to run .bat file with python code: ImportError: Unable to import required dependencies: numpy:

I'm using Anaconda. I created an environment called ENGINEERING. In than environment I installed python 3.6, pandas 1.1.3, spyder 3.3.6, numpy 1.19.2, and many more. The base environment has these packages also but not necessarily the same version. Within the ENGINEERING env I created a python script in Spyder that runs without any issues when I run it in spyder. Then, I want to automate that script by creating a .bat file and then using that to automate via windows task scheduler. My .bat looks like this:
"C:\Users\alopo000\Anaconda3\envs\engineering\python.exe" "C:\Users\alopo000\Files\Python\Valid\Portf.py"
pause
when I run the .bat I get an error message:
ImportError: Unable to import required dependencies:
numpy:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.6 from "C:\Users\alopo000\Anaconda3\envs\engineering\python.exe"
* The NumPy version is: "1.19.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed: The specified module could not be found.
I've tried many things to fix this. I went to the website they suggested and couldn't find anything there. I uninstalled pandas and numpy and reinstall them again but still, same error. The one thing I haven't tried is to fix the VARIABLE PATHS, mostly because I've read in many places not to change those. I can change them if that's what it is, but I would like to understand first why it is not recommended. I read it can create issues with other versions of python but not sure if that's what it is.
Do I need to activate the environment in the .bat file? is the problem that the .bat file is trying to run it outside the environment? Any help would be appreciated.
You will need to upgrade/change your base Python & numpy version installations to match those specified (3.6, 1.19.2). I had the same issue and same situation as OP (write/dev program in a virtual Spyder environment "spyder-env", then automate .py file with WTS). I tried copying over & running the 'activate.bat' in the /scripts/ folder of the virtual environment but that didn't work. In my situation, my conda spyder-env was Python = 3.9.12 and numpy = 1.21.5.
I ended up upgrading my base global Python version (conda install) for Python which changed from 3.8.3 and did the same with numpy (had to downgrade). I'm not sure if this is exactly necessary, why this works, or if it may cause problems down the line (I was about to just re-install conda).
The appropriate .bat file should be something like this once you do that:
call "C:\Users\alopo000\Anaconda3\Scripts\activate.bat"
call "C:\Users\alopo000\Files\Python\Valid\Portf.py" %*
REM Uncomment below to debug
REM pause

How to update fsspec in Pandas

I am trying to use the Pandas read_csv method. Everything was working fine. I saved everything and started to work on it the next day but then I kept getting this error:
ImportError: Pandas requires version '0.7.4' or newer of 'fsspec' (version '0.6.2' currently installed)
I have updated pandas to the latest version twice to make sure that it is up to date. I am unsure what to do to troubleshoot going forward, any suggestions are appreciated!
Just do on command prompt
pip install fsspec=0.7.4
It will work fine.
You would need to install fsspec==0.8.2 (or a newer version than 0.6.2) in your project to continue working with pandas

Problems to use pandas within Visual Studio Code

I have installed pandas then tried to import pandas
Code:
import pandas as pd
print("Test Pandas")
Error Type:
Exception has occurred: ModuleNotFoundError
No module named 'pandas'
I already have Python, Pip and Pandas installed, but when I am trying to use the pandas within Visual Studio Code the error bellow appears.
Someone could help me, please?
Try entering the terminal in VS code (CTRL + ~) and enter a python environment (type python and then hit enter). From there try the command:
help("modules")
That will show you packages installed in your current project environment. If you don't see pandas, it's due to difference in environment and just need to pip install pandas again from inside the project env.
Side note: one thing that can help to avoid this kind of problem for you in the future is using virtual environments

Categories