When I use pip install skforecast in Jupyter, the install completes successfully.
Next, when I use from skforecast.ForecasterAutoreg import ForecasterAutoreg I get the following error:
ModuleNotFoundError: No module named 'skforecast'
I have tried pip and pip3 for all 3 suggested installs in the docs: https://joaquinamatrodrigo.github.io/skforecast/0.4.3/index.html
Any advice on how to fix this would be greatly appreciated.
I had the same problem when trying to run a script in JupyterLab from a virtual environment. What worked for me was to specify which kernel to use. To do that:
Navigate to your virtual environment directory and activate it. In my case on windows 11, in a terminal: {virtual_environment_path}\Scripts\activate.bat
pip install ipykernel if you don't have it already installed
In the same terminal, navigate to your project folder (typically the parent directory of your virtual environment) and python -m ipykernel install --user --name={your virtual environment name}
Open your project with JupyterLab/Jupyter, go to the kernel menu and click "change kernel".
Change Kernel Menu
There you can select the kernel with you virtual environment name in it. Now your kernel can access all and only the packages installed in your virtual environment.
Select the virtual envitornment kernel
Anyway, credit to this guide, which I almost copypasted:
https://www.linkedin.com/pulse/how-use-virtual-environment-inside-jupyter-lab-sina-khoshgoftar
Related
I am running VS Code on a Mac OS. I have installed Jupyter extension but I'm unable connect to my Python virtual environments. When I create a new virtual environment with Anaconda, VS Code appropriately recognizes the virtual environments but the ones I create manually do not work.
I have no problem launching jupyter notebook in the browser from the command line but I'd like to be able to use VS code. Also, I have no issues running plain python scripts in the virtual environment I have created.
Any help is greatly appreciated!
Thanks!
I have tried the following steps:
Create a new virtual environment:
cd ~/.virtuaenvs/
python3 -m venv new_venv
Activate the new virtual environment:
source new_venv/bin/activate
Install ipykernel and jupyter
pip install ipykernel jupyter
Add environment to kernels list
python3 -m ipykernel install --name "new_venv" --user
Restart VS code. But the new_venv does not show in my list of kernels when opening a Jupyter notebook.
I did the same in my vscode. Unfortunately, I can get the kernel directly from the list.
I suggest you manually add the virtual environment path in the settings.json file (use shortcuts "Ctrl+shift+P" and type Preference: Open user settings(JSON)):
"python.venvPath": "${fileDirname}/new_venv/Scripts/python",
There are many questions like this (e.g. Conda environments not showing up in Jupyter Notebook, Python: modul not found after Anaconda installation, https://askubuntu.com/questions/1271137/importing-anaconda-libraries-not-working). I have tried their solutions but to no avail.
In short, I have conda installed. I have installed jupyterlabs and nb_conda_kernels in my base environment. When I create a new conda env via a file, the environment is not listed in jupyter automatically. I can add it via
python -m ipykernel install --user --name <env-name>
but then after I restart jupyter and switch kernels, when I try to import a python module from it, it says module not found.
What do I need to do to fix this? I do not want to add jupyterlabs to every env.
NOTE:
when activating the env in the terminal the path is correct, e.g. /opt/anaconda/anaconda3/envs/<env-name>/bin
when using the env in the terminal, the pack is there.
when using the kernel in Jupyter, the module is not there.
I am receiving the following download error when I attempt to install Jupyter Notebook on Windows:
ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'C:\\Users\\*redacted*\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python38\\site-packages\\jedi\\third_party\\django-stubs\\django-stubs\\contrib\\contenttypes\\management\\commands\\remove_stale_contenttypes.pyi'
I located the commands folder and the file remove_stale_contenttypes.pyi was not present. I did a file search for my CPU and the file was not found in another location.
I have never used python, pip, or jupyter before. I am attempting to install them in preparation for a class.
Make sure the maximum file path length limitation is turned off on your windows machine.
In the Registry Editor, use the left sidebar to navigate to the following key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
On the right, find a value named LongPathsEnabled and double-click it. If you don’t see the value listed, you’ll need to create it by right-clicking the FileSystem key, choosing New > DWORD (32-bit) Value, and then naming the new value LongPathsEnabled.
In the value’s properties window, change the value from 0 to 1 in the “Value data” box, and then click OK.
Here is a link to an article describing how to do this: https://www.howtogeek.com/266621/how-to-make-windows-10-accept-file-paths-over-260-characters/
Try uninstalling virtualenv or pipenv (whichever you are using) and then reinstalling. If this doesn't work try installing conda. There are two versions of it:
Anaconda
Miniconda
I would recommend going with miniconda as it is a lightweight installation but does not have a GUI. Here is the link to install it. Afterwards to create a virtual environment do this:
Go to the conda terminal or cmd and type in conda create --name myenv(and change the name of the env to whatever you like). This should create your environment.
Afterwards to activate it, type in conda activate name (Name is again what you put up there) Thats it. You have now created a conda env. So afterwards, whenever you want to access this enviornment again, use the activate command.
As for installing jupyter notebook, first activate your env and the run this:
conda install -c conda-forge notebook
This should install jupyter notebook in that environment. To access that jupyter notebook again, always activate the enviornment and then type in jupyter notebook. If this seems a bit too much for you, you should actually have a program named jupyter notebook(env name) in your computer after you successfully installed jupyter. Just click on that and it will handle everything for you.
Please let me know if you have trouble doing this.
The easiest way to setup Jupyter Notebook is using pip if you do not require conda. Since you are new to python, first create a new virtual environment using virtualenv.
Installing pip (Ignore if already installed):
Download get-pip.py for Windows and run python get-pip.py
Installing virtualenv: pip install virtualenv
Creating a new virtual environment: virtualenv your_env_name
Activate Virtualenv: your_env_name\Scripts\activate
Installing Jupyter Notebooks: pip install notebook
You can launch the notebook server using: jupyter notebook
I could use some clarification regarding anaconda envs and the installed packages. I have just began using environments other than the base to keep my installations clean.
I just deleted my anaconda3 folder, installed it from scratch, made a new environment and tried to run a jupyter-notebook.
When reading excel via pandas I get the error Missing optional dependency 'xlrd'
prompting me to install xlrd via conda or pip.
So I open the terminal, activate the env I’m working in and install it using conda. I close the JN from the terminal, reopen it and run the same code. The problem persists.
I repeat the procedure, this time indicating the name of the env at the end. Problem persists.
I checked which python in the terminal, it is indeed the anaconda3/envs/newenv/bin/python
I do the same (in the new env) using pip. I use the command .../anaconda3/envs/newenv/bin/python -m pip install xlrd. I get the message Requirement already satisfied: xlrd in ./anaconda3/envs/newenv/lib/python3.7/site-packages (1.2.0).
I even tried installing the package inside the notebook using !conda install xlrd, still I get the same error.
Finally, I open Jupyter via the base env, and the package works there perfectly.
I have no idea why I can’t install this under the newenv, which was the point of having local envs after all.
Thanks heaps for your help!
You need to install the kernel in Jupyter to be able to use it.
jupyter kernelspec list
That command will give you the list of kernels you have. I am assuming it only shows you Python3
You will now need to install a kernel. Remember to do this while inside your virtual environment
python3 -m pip install ipykernel
python3 -m ipykernel install --user --name <your-new-kernel-name>
You should now see this in Jupyter notebook. Select the kernel in Jupyter and you should be good to go.
Another thing you may want to try is to install Jupyter while inside your virtual environment. While inside your virtual environment, you could do:
python3 -m pip install jupyter lab
and then while still inside your virtual environment, run jupyter after checking which jupyter. It should solve your problem as well.
I am at a Python boot camp this weekend but I have not been able to even use Python on my computer because of this issue. All my instructors are stumped too.
The issue is that I get the ModuleNotFoundError on Jupyter with multiple different packages, including Pandas and Requests (but oddly enough, BeautifulSoup and CSV work fine.)
Here is how I start a new Jupyter file:
Create a new directory
Install jupyter and pandas with this command: pipenv install jupyter pandas
Activate virtual environment: pipenv shell
Launch Jupyter: jupyter notebook
Create new Python 3 notebook
At this point, I try a command like import pandas as pd and get back the ModuleNotFoundError.
I am using Python version 3.6.5.
Attempts to fix this that have failed:
double-checked that pandas is installed in my virtual environment with pip graph
created completely new directory
pipenv install jupyter pandas --skip-lock
Uninstalled everything system-wide with these commands:
pip freeze > requirements.txt
pip uninstall -r requirements.txt -y
Updated pandas
Used virtualenv instead of pipenv
virtualenv first-python-notebook
cd first-python-notebook
cd Scripts
activate
cd ..
pip install jupyter pandas
I tested that pandas could be imported when I used python in the command shell (yes) -- still didn't work on Jupyter.
My instructor thinks the issue is that system-wide packages are interfering with virtual ones but we have been working for hours and cannot figure out how to fix this.
Any help would be greatly appreciated. Please include detailed instructions as I am a beginner.
If you're getting 'ModuleNotFoundError: No module named xxyyzz' in jupyter, but the module can be imported by running python via the pipenv shell (pipenv run python -c "import xxyyzz; print(xxyyzz.__version__)":
it's probably jupyter's python path isn't set properly in the kernel config file: ..\jupyter\kernels\<myProjectName>\kernel.json
the kernel needs to be created within the pipenv shell to pick up the right path
With a fresh pipenv install:
pip install pipenv
cd <project directory>
export PIPENV_VENV_IN_PROJECT=1 # creates .venv in project directory
pipenv --python=/path/to/python --site-packages # use python executable for your system or environment
pipenv shell # work in project's virtual environment
python -m ipykernel install --user --name=<myProjectName> # create jupyter kernel for project
exit # exit project's virtual environment
pipenv run jupyter notebook # start jupyter from project directory
in jupyter, choose the kernel "myProjectName"
this post provides additional explanations
Why don't you try to install ipykernel with Anaconda virtual env?
It'll will be more easy to handle.
If you haven't previously used Anaconda before, just go to the official website
https://www.anaconda.com/download/ and download the newest version for your OS.
Then, follow these steps.
Execute Anaconda prompt.
Type 'conda create -y -n $ENVIRONMENT_NAME ipykernel'
Type 'conda activate $ENVIRONMENT_NAME'
Type 'conda install -y $PACKAGES_TO_BE_INSTALLED'
Type 'python -m ipykernel install --user --name $NAME --display-name $IPYKERNEL_NAME'
This ipykernel name will be presented on your list of kernels in jupyter notebook.
You can findout the list of kernels installed by typing jupyter kernelspec list.
Hope this helps!
Thanks for the advice. However, I was advised specifically not to install Anaconda -- can't quite remember the reason but I think it's because, basically, if I ever decided I wanted to use something else then it would be a real headache to switch. I'm happy to hear your reasoning if you disagree with that.
I ended up solving the issue by uninstalling every package both within the virtual environment and the larger computer system, then re-installing it in both places. It worked, but I'm sort of confused as to what the point of a virtual environment is, if I still had to install everything twice.