I can install pip packages inside IPython by writing !pip install name. I am however unable to do this with conda. The following example just gets stuck when executed in Jupyter Notebook !conda install -c anaconda pillow -y.
Anyone who can explain why?
There is a good post found here : https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/
It talks about issues using conda within notebooks and suggests
import sys
!conda install --yes --prefix {sys.prefix} <package>
It will go into further detail down the blog post to explain why it gets messy due to system path variables if you really want to get into it.
Related
I need some help with some weird things happening in jupyter.
It all started when I was trying to install tweepy, the package was installed successfully but it doesn't work when I try to import it in jupyter and it outputs this error:
ImportError: No module named 'tweepy'
The package was installed via pip, first thing I checked was if the package was really installed in the environment or not..and it was. In short I tried the following:
I uninstalled the package with pip uninstall tweepy and then installed it again with pip install tweepy.
I then tried to install it with conda install -c conda-forge tweepy
I then tried to install it from inside the notebook with !conda install -y -c conda-forge tweepy
Well..nothing from the above did work, unfortunately. and it was getting really frustrating!
I found this post which suggest this:
import sys
!{sys.executable} -m pip install package
It did work. but here is the weird thing: whatever package I import ,even non-installed packages!, the cell just work without any errors! and when I check the list of packages installed in a totally new environment that I created to test this, which does not have any packages installed, with !conda list I get empty list as expected but still any package I import still work!
So, can anyone help me understand what just happened?
You should not use pip if you are using Anaconda. Create a virtual environment by typing: conda create -n yourenvname python=x.x anaconda where yourenvname is the name of your virtual environment and python=x.x is the version number of python you wish to use like python=3.8. Now after this activate you virtual environment. The type conda install package. And see if it works.
I followed instructions given in the TensorFlow website to install tensorflow_hub and installed it within a conda environment.
$ pip install "tensorflow>=2.0.0"
$ pip install --upgrade tensorflow-hub
I ran the above in anaconda prompt
But I'm still getting ModuleNotFoundError for 'tensorflow_hub'.
Any help here is appreciated. Thanks in advance
First thing
Check whether you have installed tensorflow_hub within that environment
conda list
If you can not find it there, maybe you have been installing it to another environment which does not matter, just install it again here.
pip install tensorflow_hub
You have probably done that so most likely you are using another kernel within your jupyter notebook, so either go to the environment of that kernel and install your package there. Or the preferred way, install your current environment yourenvironment as a new kernel and use that one in your jupyter notebook
python -m ipykernel install --user --name=yourenvironment
Now start your jupyter notebook and enjoy your package
I am trying to use dask-jobqueue on a high performing computer (HPC).
Following the documentation on dask-jobqueue here, I am trying to install dask-jobqueue on an instance of a Jupyter Notebook in the HPC with the following code:
install dask-jobqueue -c conda-forge
but I am getting the following error:
File "<ipython-input-10-cad837f248c1>", line 1
install dask-jobqueue -c conda-forge
^
SyntaxError: invalid syntax
I have attached a screenshot here:
I am not sure what I did wrong and what do I do now? Would really appreciate any help.
Many thanks in advance.
It looks like you want to install dask-jobqueue from the conda-forge repository using conda as stated in the docs. But then you should adhere to the full command with the correct syntax:
!conda install dask-jobqueue -c conda-forge -y
Notice the leading ! to execute command line statements directly from the notebook. I also added the -y option of conda to automatically approve the installation of conda packages within a Jupyter notebook.
I am assuming the conda environment is installed on the computer. Otherwise, you should use the alternative with pip:
!pip install dask-jobqueue --upgrade
I'm trying to use conda to set up one of my projects. I installed openCV by conda install -c conda-forge opencv. When I run conda list, I can see openCV in the list. Running python -i and then import cv2 works, but when I open up Jupyter Notebook and navigate to that folder (I have to do it this way because running jupyter notebook in the directory also pulls up an error), and open up a notebook which imports cv2, I get an error. Why is this happening, and how would I solve it? Any kind of help will be greatly appreciated.
So as I said before, I wasn't able to start Jupyter Notebook from the command line, I had to start it from the start menu and navigate to my folder. Because of that, my notebook wasn't working in the conda environment that I created. I fixed that by running python -m ipykernal install --user --name <env_name> --display-name "<display_name>". I had to conda install ipykernel. It works now. Thanks for the other answers.
Usually that indicates that the notebook is running with a different Python or in a different environment from Python in the command prompt. Check sys.executable to see which Python it's running in, and sys.path to see where it's looking for imports
Everybody says that pip installing from notebook is not the best practice, but maybe for a fast try it would do the thing:
# Install a conda package in the current Jupyter kernel
import sys
!conda install --yes --prefix {sys.prefix} packagename
# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install packagename
I used it from Install python packages on Jupyter Notebook and it worked for me.
Step 1: Activate environment before running
conda activate <environment-name>
Step 2: Install ipykernel
conda install -c anaconda ipykernel
Step 3: Add the conda environment to ipykernel
ipython kernel install --name <environment-name> --user
Step 4: Install your package
conda install -c conda-forge opencv
References:
How to add your Conda environment to your jupyter notebook in just 4 steps
Conda environments not showing up in Jupyter Notebook
It is unclear to me how to install Matplotlib's Basemap on Windows. Maybe the question is straightforward, I need some help.
I followed this tutorial. As far as I understand, first, GEOS and PROJ4 should be installed, and lastly matplotlib-1.4.3.win-amd64-py2.7.exe should be executed.
I get stuck with GEOS. I downloaded source code of geos-3.5.0, "untarred" it, then I go to a Command Prompt, change directory to geos-3.5.0 and run this:
export d://test
but it does not work.
Use this download for basemap on Windows.
It worked for me:
pip install basemap-1.0.8-cp34-none-win_amd64.whl
Assuming you're in right directory of course.
This is the alternate solution that might useful for anaconda users
For only Anaconda Users, they can get it to install on the local machine through the following command:
conda install basemap
This will auto-install all required dependency packages.
Here also, Assuming that User are at the right directory to install any module.
I had the same issue as I pip installed and then conda installed and then had to do a clean install as dependencies were a mess.
At that time I solved my problem by using Google Colab and installing the following:
!apt-get install -q libgeos-3.5.0
!apt-get install -q libgeos-dev
!pip install -q https://github.com/matplotlib/basemap/archive/master.zip
!pip install -q pyproj==1.9.6
I would also recommend reading Importing-of-Basemap-in-Google-Colab as it helped with Colab installation.
while importing like (from mpl_toolkits.basemap import Basemap) I was getting error.
For me This Worked Like charm:
pip install basemap