Importing updated package in python - python

I've updated scipy package in my environment from the terminal and started the Jupiter notebook.
In a cell I run
scipy.__version__
but that shows the previous version which doesn't have some properties I need. What can be the cause of the problem?
screenshot

There might be several versions of the package still installed on your machine.
Restart completely the Jupiter notebook (even your computer). Make sure the jupyter notebook is runned in the correct environment where you have updated the package if you are using for example anaconda.
Search for the package name a list all the folders in which is it present.

Related

Jupyter notebook and anaconda environment bug

I located a really weird behavior of Jupyter and caused me to reinstall it but the problem persisted.
I have a Windows machine where I have installed anaconda (the latest version). There are two environments:
(base) Which contains nothing special maybe seaborn pandas etc. and is on python version 3.8.12.
(tf-gpu) Which contains tensorflow-gpu and is on python version 3.9.7.
Mind you, these two environments are created directly from a fresh installation of anaconda, and I didn't touch anything except installing tensorflow-gpu.
When I launch Jupyter through Anaconda, it launches normally on the home folder "C:\User\user" for both environments i.e. correct packages installed and correct version of python on both. I can also launch an instance of Powershell through Anaconda or Windows, (always in home dir), and launch Jupyter both environments behave as they should (packages, python version). So far so good...
The problem starts when I want to launch Jupyter from a directory other than home dir. I keep all my project files in a separate partition (D:), thus I navigate to that directory through a cmd/powershell (launched through Anaconda or Win) and type "jupyter notebook". The notebooks open on that director and:
When the base env is selected the notebook reports a correct name "base"(os.environ['CONDA_DEFAULT_ENV']) and python version 3.8.12 (sys.version_info). Everything behave as base env was setup.
When the tf-gpu env is selected the notebook reports a correct name "tf-gpu" but I get a python version 3.8.12, which is completely wrong! It should be 3.9.7. I can't import tensorflow since I get an error. Essentially I am in the base env without knowing it.
I then check in the same cli window (tf-gpu) that launched jupyter and python --version reports 3.9.7 and of course can import tf run it etc.
Jupyter just reports the environment name but in reality it uses the base environment even though it launched from said env. How can this change?
Why does Jupyter works normally when launched from the user directory?
If this is not solved easily, what is a workaround? Jupyter doesn't recognize symbolic links, and thus I can not navigate to another directory if it is not a subdirectory of home.
Finally, I also tried adding the env as kernel through python -m ipykernel install --user --name tf-gpu --display-name "Tensorflow GPU (tf-gpu)", but it doesn't seem to change a thing.
Update 1:
Of course I activate the tf-gpu through conda activate tf-gpu and check the python version and tensorflow (correct results), the problem is when launching jupyter notebook. The notebook reports the tf-gpu env but wrong python version and tf is missing.
Update 2:
After some searching around it seems that jupyter notebook has much trouble selecting a python version if multiple versions of python are installed in the system (in my case 2, 1 on each environment environments). Which is ridiculous if you think that that's why we are using environments for...
The reason you are having this problem I’m guessing is because your launched jupyter notebook from your conda base environment. You will see a (base) in your comment prompt.
To remedy this, When you use the command prompt to launch, do conda activate tf-gpu before you launch Jupyter notebook, now check if your versions are correct.
What I did and worked was run ipython3 notebook in the environment which launched the notebook server and everything was working properly correct environment name and correct python version and packages (tensorflow is working as it should). This must have updated some configuration files since I can now run jupyter notebook from a different folder and the gpu-tfu env works correctly.
Please remember that these problems were occurring only if I was launching jupyter outside the home directory (C:\User\user) on a different partition. Also keep in mind that this is a Windows installation and more complicated things may be happening with user paths, environments, etc than in linux.

How can I get a Jupyter Notebook to see the modules in the environment that it was opened in?

I am attempting to import cartopy into a notebook but am running into issues. If I do a "conda install cartopy" in my base environment, I get the frozen/flexible solve issue (https://github.com/conda/conda/issues/9367). When I open a new environment and do a "conda install cartopy", it seems like everything works. "conda list" shows version 0.18.0 in that environment. Then I open a Jupyter Notebook from within that environment and try to import it into the notebook but originally got the response "no module named cartopy". I tried fiddling with my environments and settings based on feedback on this page (In which conda environment is Jupyter executing?), but now the error is "no module named numpy"! Can someone please help me understand why the notebook isn't seeing these modules? Thank you.
Are you certain that numpy is installed in this new environment?
Given that you are using the Anaconda distribution of Python, you should be able to view/configure your environment and it's installed modules using the Anaconda Navigator. Here you can see a full list of all installed modules, and via the terminal/console, launch a Jupyter Notebook from not only within a specific environment, but within a specific directory!
On the left hand side, you can choose the environment that you want to use to start Jupyter Notebook, and on the right you can view all of the installed modules in that environment. Make sure that jupyter, numpy, and cartopy are all listed as installed packages.
To make sure that I am launching Jupyter from my desired environment, I always launch it directly from the terminal. I "Open Terminal" with my environment, "cd" into the directory that I want to use, and then use the jupyter notebook or jupyter lab command.

Importing library error: No module named <pkg>

In the past, I downloaded an open-source package through pip when I was just using it and it worked fine but I have recently started to help with the development of the package so I cloned the github repository onto my laptop and am now having troubles. I checked out and pulled the changes to a new branch in the github repository to work with some changes someone else made but my Jupyter Notebook was still using the old version of the package as I couldn't access the new methods in the notebook I was working in. If I open the code through 'open .' when in the directory, I can see that it is the proper code that I need to run but Jupyter notebook was not running that code. I then ran 'pip freeze' in my terminal and saw a package was still installed there so I ran 'sudo pip uninstall ' and uninstalled the package from pip. Although now, when I try to import the package into my Jupyter Notebook I get the error where there is:
No module named <package name>
Does anyone know why this is happening and how I can fix it? I would like to be able to use the version of the code of which branch I am in currently.
EDIT:
The package library is stored in /Users/myName/pkg. I am trying to access this through the 'import ' statement in Python. I am running this import statement through a Jupyter notebook in Jupyter lab. Jupyter lab is installed under python3.7/anaconda3/bin/jupyter-lab. I used to have another version of this open-source library installed which I installed using pip, but I recently uninstalled it as I thought that was causing the problem.
I also ran
sys.executable
and it returned '/anaconda3/bin/python'
EDIT 2:
I tried following the solution from this post but when I activated my new environment created, my entire jupyter lab local-host page just kept refreshing constantly and would not load anything. Although when I do not activate that environment I can run my old jupyter lab fine.
EDIT 3:
SOLUTION:
The solution I linked above worked for me, although I also had to update my Jupyter Lab in the new conda environment to stop my page from being infinitely refreshed.

Jupyter file open doesn't appear in the new file list

I fell like I'm might be doing something really silly here but I've been researching for 30 mins and can't find an answer.
I'm working in Pycharm on python version 3.7. In pycharm I have created a new project and within have set a venv with python 3.7 as the interpreter. I then went to settings and installed the jupyter meta package version 1.0.0. I got the message "Package 'jupyter' installed successfully."
When I go to create a new file however I don't have the option to create a jupyter file, only a .py file.
I've tried restarting my computer (I'm on a mac) and I have tried setting up the project in a conda environment, neither made any difference. I also thought am I actually installing jupyter-notebook so I then installed jupyterlab 1.2.4 and I still can't create a jupyter-notebook file.
Any ideas?
Thanks
Only the professional version of PyCharm supports Jupyter notebooks.
Here is a full tutorial on how to configure PyCharm to use Jupyter notebooks:
Jupyter notebook support in PyCharm

Pycharm jupyter notebook wsl: Jupyter package is not installed

I would like to use Jupyter notebook inside Pycharm. The project interpreter is a python2.7 from a virtual environment inside WSL (ubuntu 18.04).
The Jupiter package is correctly installed inside the virtual environment (I can run it by jupyter notebook).
My problem is that when I want to use Jupyter notebook inside Pycharm, I get the following error: Run Error Jupyter package is not installed (see picture).
Any idea what's going on here?
I had this problem in Python 3. Below are the steps I took to resolve the issue; I believe they should resolve the issue for you too:
I had Jupyter Lab installed. Pycharm only works with Jupyter Notebook. Long story short, if you have Jupyter Lab installed you need to uninstall all your packages using:
$ pip freeze | xargs pip uninstall -y
Restart your computer
Follow Jupyter Notebook installation instructions
Make sure WSL is set up through pycharm instructions: wsl pycharm instructions
In Pycharm, open an .ipynb file. Click the dropdown that says "Managed Jupyter server" It's right above the text editor. Select "configure Jupyter server". Check configured server.
In your wsl terminal, type jupyter notebook. Copy and paste the text that looks like: http://localhost:8888/?token=874asdf687asd6fasd8f74ds6f4s9d8f7sddf into the cofigured server box in Pycharm.
That's it. You should be able to run the jupyter cells in pycharm now.
I have Pycharm 2020.3 For me the issue was I was using a virtual environment with "inherit global site packages." I had Jupyter installed in global site packages but NOT the virtual environment.
Once I installed Jupyter within the virtual environment Jupyter notebook worked. Not sure why inheriting Jupyter from global packages wasn't working for me.
The above solution using a designated url with token seems to work with older versions of PyCharm. A simpler solution is to upgrade to the latest PyCharm. I no longer had an issue with the auto server using PyCharm 2019.3.2 (Mac)
I had this problem with Datalore plugin enabled on 2020.2 linux, running on bare metal but displaying to a remote X server (probably doesn't matter). My solution was to disable the Datalore plugin (it's enabled for professional pycharm by default).
This way I was still able to use the "managed" auto-start version with better integration / debugging vs the "configured" option (or at least with less hassle).
Note since it's been a year, my problem is probably different than OP.
This happened for me, when the interpreter was a remote one. I fixed this by changing the interpreter to one from a local env.
This can be done by selecting the Configure Jupyter Server.
I also meet this problem,and i solved it
i create the new project with the global sit-packages like below
then i meet the problem
i create the new project with no global sit-packages and install jupyter notebook in the virtualenv
then the problem is gone

Categories