Why does installing Tensorflow with conda ruin matplotlib? - python

Starting from a new anaconda environment, it looks like this (summarized, not a full paste):
[myenv]$ python
Python 3.8.8 ...
>> import matplotlib.pyplot as plt
>>
[myenv]$ conda install tensorflow-gpu
...
[myenv]$ python
>> import tensorflow
>> tensorflow.__version__
'2.4.1'
>> import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
>>
[myenv]$ conda install matplotlib
...
[myenv]% python
>> import tensorflow
>> import matplotlib.pyplot as plt
<tons of traceback>
RunTimeError: the sip module implements API v12.0 to v12.4 but the PyQt5.core module requires API v12.5
How can I have tensorflow and matplotlib at the same time?

Do you have the complete traceback? Based on the Error you posted, it seems like its a dependency issue on the sip module. I'll recommend using you own virtualenv instead of anacondas.
FOR CREATING YOUR OWN VIRTUALENV:
open terminal
go to the directory you want your project to be
pip install virtualenv
virtualenv venv
source venv/bin/activate (for linux or mac)
pip install tensorflow
pip install matplotlib
pip install <whatever library you want>

Related

Networkx & Jupyter Notebook using pip AttributeError

Hi everyone, I'm trying to create a network visualization with python using the networkx package. Unfortunately I'm getting a "AttributeError: module 'scipy.sparse' has no attribute 'coo_array'" at the end of my code. I've tried to fix it but every help in the internet points towards upgrading pip or conda which I've done and still get the same error. I'm using jupyter notebooks - any help would be greatly appreciated!
#Prerequisites
import sys
!{sys.executable} -m pip install --user networkx
!{sys.executable} -m pip install --user numpy
!{sys.executable} -m pip install --user pandas
pip install notebook --upgrade
conda upgrade notebook
import networkx as nx
import numpy as np
import pandas as pd
from pathlib import Path
from pandas import DataFrame
#Read in Source File - NB this must match the schema requirements
df_InputData = pd.read_excel("/Users/paulkruse/Desktop/FR/Fr1.xlsx")
Src_Column = 'Source ID'
Tgt_Column = 'Target ID'
print(df_InputData);
#Nodes are positioned using the Fruchterman-Reingold force-directed algorithm.
Q = nx.Graph()
arr_SrcTgt= np.array(df_InputData[[Src_Column, Tgt_Column]])
print(arr_SrcTgt);
Q.add_edges_from(arr_SrcTgt)
dict_Coords = nx.spring_layout(Q)
It seems that your scipy version is out of date. The most recent version 1.8.1 certainly has coo_array function. One way to resolve this should be to upgrade scipy. If you're doing this from inside jupyter notebook, then use
!pip install --user scipy==1.8.1
Make sure to restart kernel after installation.

Module Not found when importing PyCaret in Jupyter

I'm trying to learn PyCaret but having a problem when trying to import it in Jupyter Lab.
I'm working in a virtualenv and installed pycaret via pip:
pip install pycaret
I can confirm its installed via pip list:
prompt-toolkit 3.0.7
protobuf 3.13.0
py 1.9.0
pycaret 2.1.2
pycparser 2.20
The very first line in the notebook is:
from pycaret.nlp import *
however this results in:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-3-7c206b4a9ead> in <module>
----> 1 from pycaret.nlp import *
2 import psycopg2
3 import sys, os
4 import numpy as np
5 import pandas as pd
ModuleNotFoundError: No module named 'pycaret'
I'm pulling my hair out trying to figure this out and can't find anyone else with something similar.
I've tried to import via the python shell as well and that works perfectly.
You should create a seperate environment for installing time series alpha module
after creating a new environment and switching into
pip install pycaret-ts-alpha
and then you will be able to access
https://towardsdatascience.com/announcing-pycarets-new-time-series-module-b6e724d4636c
I forgot that you had to install modules via Jupyter.
Following this guide: http://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/index.html
Installing like so:
# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install numpy
Got it working
First Create a new environment conda documentation
Second Download the Pycaret with this instruction
Third check your sklearn version is greater thansklearn>=0.23.2.
Because if it's greater PyCaret is not compatible with that.
Nothing works for you? Download directly from github with this command
pip install git+https://github.com/pycaret/pycaret.git#egg=pycaret
I read on the tutorial page of pycaret that to install it through a Jupyter-notebook you should add an exclamation mark in front of the python command in the Jupyter-cell:
!pip install pycaret

ModuleNotFoundError: No module named 'numpy' - Jupyter Notebook

I'm facing weird issue in my Jupyter-notebook.
In my first cell:
import sys
!{sys.executable} -m pip install numpy
!{sys.executable} -m pip install Pillow
In the second cell:
import numpy as np
from PIL import Image
But it says : ModuleNotFoundError: No module named 'numpy'
I have used this command to install Jupyter notebook :
sudo apt install python3-notebook jupyter jupyter-core python-ipykernel
Additional information :
pip --version
pip 20.2.2 from /home/maifee/.local/lib/python3.7/site-packages/pip (python 3.7)
python --version
Python 3.7.5
Thanks to #suuuehgi.
When Jupyter Notebook isn't opened as root:
import sys
!{sys.executable} -m pip install --user numpy
I've had occasional weird install issues with Jupyter Notebooks as well when I'm running a particular virtual environment. Generally, installing with pip directly in the notebook in this form:
!pip install numpy
fixes it. Let me know how it goes.
Restarting the kernal from the Jupyter Notebook solved this issue for me
I had a similar issue. Turns out I renamed an upstream path. And I hadn't deactivated my conda env first. When I deactivated the env.
conda deactivate
Then when I activated it again, everything was as it should have been.
conda activate sample
Now I am seeing other issues with jupyter themes... but its not impacting my numpy code. So, at least I fixed the "ModuleNotFoundError: No module named 'numpy'" error
I have the same problem. My numpy is installed, I am using the same folder as usual.
If I try 'conda deactivate', I get the message:
ValueError: The python kernel does not appear to be a conda environment. Please use %pip install instead.
I added a print of the 'pip install numpy' result and the 'Module not found error' after
Here is a solution which worked for me:
lib_path="c:\\users\\user\\python_39\\lib\\site-packages\\"
MODULE_NAME = "module_to_import"
MODULE_PATH = lib_path+MODULE_NAME+"\\__init__.py"
import importlib
import sys
spec = importlib.util.spec_from_file_location(MODULE_NAME, MODULE_PATH)
module = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = module
spec.loader.exec_module(module)
import module_to_import

Get dependency file to host Jupyter notebook on Binder?

I am trying to export my dependencies to a requirements.txt or environment.yml file for pip or conda respectively - in order to host a Binder notebook.
How can I get only the dependencies that my notebook is using?
When I tried pip freeze or conda env export, I get all my installed packages, which leads to errors when building the Docker environment.
You might want to try watermark:
Install:
pip install watermark
Then, in your notebook:
# Load the extension
%load_ext watermark
# import your libraries
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# Determine the dependency version
%watermark -p numpy,matplotlib,seaborn
The results will look like this:
numpy 1.14.3
matplotlib 2.2.2
seaborn 0.9.0

Anaconda installation not finding packages

This one is best shown through what I'm trying to do and what is going on.
In my python file, I want to import seaborn.
It's available to install via conda.
(me_dev)[me#ip-***]$ conda install seaborn
Fetching package metadata: ....
Solving package specifications: ............................
# All requested packages already installed.
# packages in environment at /home/me/miniconda/envs/me_dev:
#
seaborn 0.7.0 py27_0
(me_dev)[me#ip-***** ****]$ which python
~/miniconda/bin/python
(me_dev)[me#ip-****]$ which ipython
~/miniconda/bin/ipython
Now if I start iPython and import seaborn:
In [1]: import seaborn
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-085c0287ecb5> in <module>()
----> 1 import seaborn
ImportError: No module named seaborn
Also, pip is not working either. It's not reading packages from pip.
(me_dev)[me#ip-*****]$ pip install jellyfish
Requirement already satisfied (use --upgrade to upgrade): jellyfish in /home/me/miniconda/lib/python2.7/site-packages
Yet:
from jellyfish import jaro_winkler ImportError: No module named jellyfish
Edit:
sys.path looks like so in iPython
['',
'/home/me/miniconda/bin',
'/home/me/miniconda/lib/python27.zip',
'/home/me/miniconda/lib/python2.7',
'/home/me/miniconda/lib/python2.7/plat-linux2',
'/home/me/miniconda/lib/python2.7/lib-tk',
'/home/me/miniconda/lib/python2.7/lib-old',
'/home/me/miniconda/lib/python2.7/lib-dynload',
'/home/me/miniconda/lib/python2.7/site-packages/setuptools-19.6.2-py2.7.egg',
'/home/me/miniconda/lib/python2.7/site-packages',
'/home/me/miniconda/lib/python2.7/site-packages/cryptography-1.0.2-py2.7-linux-x86_64.egg',
'/home/me/miniconda/lib/python2.7/site-packages/IPython/extensions',
'/home/me/.ipython']
Here's my .bashsrc
(me_dev)[me#ip-**** ~]$ cat .bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# added by Miniconda 3.16.0 installer
export PATH="/home/me/miniconda/bin:$PATH"
# User specific aliases and functions
source activate me_dev
# added by Miniconda2 3.19.0 installer
export PATH="/home/me/miniconda/bin:$PATH"
I think which python (and which ipython) should be pointing at ~/miniconda/envs/me_dev/bin/, not at ~/miniconda/bin/ directory. When you start an python session with those binaries, they can't see your seaborn library, which is probably only installed in the environment site packages.
I'm not sure exactly how you ended up in this state, but I would recommend trying to make a new environment and see if you end up pointed at the correct binaries.
The organization your .bashrc is the problem. You're activating your virtual environment, but then giving the main miniconda bin directory precedence in your $PATH, which has the effect of partially inactivating the virtual environment.

Categories

Resources