Pandas and Numpy missing from path - Python/Pyinstaller - python

I have a fully functioning jupyter notebook (.ipynb) file that can find and import both pandas and numpy. I also have that same exact code saved as a .py file in the same exact folder.
When I try to run the .py file with VSCode or Python Shell, I get an error message saying that numpy and pandas can't be found and aren't on path.
Not sure how the .ipynb file right next to it can find these modules but the .py file can't.
Any help would be much appreciated. (The .ipynb file runs through anaconda)

Since you are hosting jupyter notebook from conda it can easily use the same environment and able to find the pandas and numpy. Try import the same py file in jupyter notebook you will be able to execute the code. You need to specify python path to environment variables which is pointing towards the one which jupyter is pointing.

Related

FileNotFoundError: [Errno 2] No such file or directory: with Anaconda Navigator

Please bear with me as I'm new. I'm currently using Spyder on Anaconda Navigator. Trying to read an excel file from a folder in my desktop like this:
import pandas as pd
Dark_Maple_1 = pd.read_excel(r'C:\\Users\maiazhang\Desktop\CNN Data\Dark Maple\Dark Maple (1).xslx')
But I keep getting this error:
FileNotFoundError.
I've triple checked that this is the correct path, so I'm confused. I guess it has something to do with me being on Anaconda Navigator. I've tried changing the working directory and even tried just reading a normal txt file with the same error. Any advice would be much appreciated.
xslx is not a file type (at least I'm betting not the one you want). Change it to xlsx and you should be fine.
After looking at your traceback error, it does say xlsx so something must be wrong either in your code's directory or your actual file's name. I have tried to recreate your error in both Jupyter Notebook (launched from terminal), Jupyter Lab (from Anaconda Navigator), Jupyter Notebook (from Anaconda Navigator) and Spyder (launched from Anaconda Navigator) and cannot recreate your error (unless I mistype xslx either in my pandas read call or renaming my file)

Why Jupyter Notebook Online Can't Read an Excel file

I am trying to load an excel file online.
This this my path directory.
C:\Users\Don.A.Charles\Downloads\Practice\sorted_data.xlsx
However, I am trying to load the file through Jupyter Notebook Online with no success
https://jupyter.org/try-jupyter/lab/
Can anyone suggest anything to amend the code to allow the program to load the data?
This is the code below
import pandas as pd
import numpy as np
from sklearn import preprocessing
import matplotlib.pyplot as plt
df=pd.read_excel(r"C:\Users\Don.A.Charles\Downloads\Practice\sorted_data.xlsx")
I am receiving the error
FileNotFoundError: [Errno 44] No such file or directory: 'C:\Users\Don.A.Charles\Downloads\Practice\sorted_data.xlsx'
You can not access local files from an online server like that.
You will need to upload the file to some storage that is accessible in https://jupyter.org/ or some external place (Google Drive/Drop box etc.) from where you can load it through http.
Sadly do not have enough experience with jupyter.org it self to know are they supporting file upload.
It might be a little daunting, but you'll have more flexibility if you run Jupyter locally, on your own machine.
The easiest way to do this is probably to install Anaconda. Then open an Anaconda prompt from the Start menu. Use the cd command to change directories to your project directory (e.g. a python_projects folder in your home directory, call it what you like). Then type jupyter notebook and now you're running locally. Then you can load the file with the command you were using before.

Jupyter Notebook creates a .txt file - and doesn't let me save as .ipynb. Manually creating a .ipynb file doens't open a jupyter notebook

I'm trying to move my data science Environment to VSCODE, it seems a really powerfull IDE to deal with multiple languages and with great versatility,
But currently I'm dealing with an annoying issue with the python and jupyter extension,
Expected behaviour
Using command palette 'Jupyter: Create blank new Jupyter notebook' it should open a .ipynb file with all the features of a jupyter notebook.
(source: https://code.visualstudio.com/docs/datascience/jupyter-notebooks)
Actual behaviour
Using command palette 'Jupyter: Create new blank notebook' it opens a jupyter notebook with all the features and the proper jupyter notebook layout, but with extension .txt.
I tried to save it as .ipynb but returns and error and don't let me save it.
When I create a file manually with 'filename.ipynb' it creates a file with the jupyter icon, but without all the features of a jupyter notebook.. it is a simple plain script file like a .py file.
I already have done a lot of web search looking for some solution, but without success.
already tried reinstall vscode and downgrade some versions of the python and jupyter extensions, but all without success.
Any help to solve this would be appreciated.
Environment data
VS Code version: 1.59.0
Extension version : Python v2021.8.1105858891, Jupyter v2021.8.1195043623
OS and version: Windows 10 64bit
Python version : Python 3.9.6 64bit

Cant read csv files using pandas in Visual Code

Python : 3.5
IDE : Visual code
Platform : win 10 64 bit
First i created a virtual env _kerasVenv and then activated the env and then installed pandas using pip.
This is my directory structure:
I added a python script in Exercise files folder where I am trying to read .csv file using pandas
test= pd.read_csv('test.csv', encoding='utf-8')
.csv file and python script are in the same folder so wrong path is not the issue.But i am getting below error:
Unable to open 'parsers.pyx': Unable to read file (Error: File not found (c:\users\anubhav.jhalani\downloads\ex_files_building_deep_learning_apps\pandas\_libs\parsers.pyx)).
Can someone explain why python is looking for pandas in c:\users\anubhav.jhalani\downloads\ex_files_building_deep_learning_apps folder and why parsers.pyx file does not exist in original pandas folder which are in _kerasVenv folder?
How can i get rid of this error?
Update: I found out while hovering on import pandas as pd statement that it is looking for pandas module in c:\users\anubhav.jhalani\downloads\ex_files_building_deep_learning_apps . Why it is happening?
I think it is easier to always give the total file path.
Instead of:
test= pd.read_csv('test.csv', encoding='utf-8')
try to use:
test = pd.read_csv('C:/users/anubhav.jhalani/downloads/ex_files_building_deep_learning_apps/test.csv', endcoding='utf-8')
this should help, you can also have a look here, what syntax you need to write it:
Windows path in Python
You can also get the full path in your windows explorer, if you are unsure where it is saved.
In my case it also wasn't able to find the file even in the same directory and with the complete path. I figured it out that this issue was happening only in my VSCode editor and when I opened the same notebook in jupyter lab it was perfectly working. So then I tried one thing that make it work for me in VSCode as well was that I put my file in the directory other than "C". For example I put my file in the "D" directory and in VSCode it becomes able to work fine.

How to create modules in Jupyter notebook and import them? Python

I've created multiple python modules as .py files in a Python IDE called Pyzo in the following path:
'C:\Users\Michael\Anaconda3\Lib\site-packages' which I can then import like regular Python packages such as pandas and numpy into my Jupyter notebook or into Pyzo.
I'm a bit lost as to how to create a module in Jupyter notebook, containing a class with say a simple function, which I can then save and import into a new Jupyter notebook file.
The examples in this link below I found extremely vague and overly complicated. Any simpler examples would help, thanks!
http://nbviewer.jupyter.org/github/ipython/ipython/blob/master/examples/IPython%20Kernel/Importing%20Notebooks.ipynb
%run ./module_code.ipynb
keep this in import section- replace module_code with your file name and then you can access functions inside that file from the new notebook.
Suppose you want to import the contents of A.ipynb into B.ipynb.
Installation
pip install import-ipynb
How to use
Place both ipynb files in the same directory. Then, in the B.ipynb:
import import_ipynb
import A
Congratulations! You can now run any functions defined in A.ipynb from B.ipynb!
The easiest way to import user created modules on JupyterLab is to Export Notebook as an executable script from File menu as in screenshot. This will download .py file to your pc or mac. Just drag that downloaded file to your jupyterlab to import.
download notebook as .py file
Now you can import and use that module in other notebooks.
import example

Categories

Resources