I'm new to Tensorflow and machine learning. I'm following some tutorials on my PC, and everything worked just fine so far, importation and test with python are OK. I tried to test my code on my Macbook. So I installed Tensorflow, Matplotlib and Pandas using Pip3 on the command prompt. But when I ran the code on my Mac I got this :
Traceback (most recent call last):
File "test.py", line 3, in <module>
import tensorflow as ts
ModuleNotFoundError: No module named 'tensorflow'
There are the output and the Pip3 list :
Result of the pip install tensorflow
pip3 show tensorflow
gave me :
Name: tensorflow
Version: 2.0.0a0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: packages#tensorflow.org
License: Apache 2.0
Location: /usr/local/lib/python3.7/site-packages
Requires: google-pasta, gast, absl-py, astor, keras-preprocessing, keras-applications, six, numpy, wheel, grpcio, protobuf, tf-estimator-nightly, termcolor, tb-nightly
Required-by:
And :
pip3 list
gave me :
Package Version
-------------------- --------------------
absl-py 0.8.0
astor 0.8.0
cycler 0.10.0
gast 0.3.2
google-pasta 0.1.7
grpcio 1.23.0
h5py 2.10.0
Keras-Applications 1.0.8
Keras-Preprocessing 1.1.0
kiwisolver 1.1.0
Markdown 3.1.1
matplotlib 3.1.1
numpy 1.17.2
pandas 0.25.1
pip 19.1.1
protobuf 3.9.1
pyparsing 2.4.2
python-dateutil 2.8.0
pytz 2019.2
setuptools 41.0.1
six 1.12.0
tb-nightly 1.14.0a20190301
tensorflow 2.0.0a0
termcolor 1.1.0
tf-estimator-nightly 1.14.0.dev2019030115
virtualenv 16.7.5
Werkzeug 0.15.6
wheel 0.33.4
I did the exact same things on my Mac that I did on my PC, but I have more than one version of Python on my Mac, maybe this is the problem, but I just don't know how to solve it.
Sorry for my English, I'm not quit used to post on forum like these, and thanks for your help, I can give more information on my problem if you want.
Related
I have run a simple neural network through pycharm, pointing it to a conda virtual environment with tensorflow and dependencies installed. When I launch a jupyter notebook from that same env the exact code aborts when I try and import tensorflow.
This is the code at the top of the notebook:
import tensorflow as tf
from tensorflow import keras
.....
I expected tensorflow and keras to load ok.
Instead I got:
`---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-3-2be7691b079e> in <module>
----> 1 import tensorflow as tf
2 from tensorflow import keras
...
ModuleNotFoundError: No module named 'tensorflow'
I added a line to list installed modules at the top of the notebook in case it was looking somewhere without tensorflow installed :
!conda list
`
And got:
# packages in environment at /home/user/anaconda3/envs/tf-cert:
#
# Name Version Build Channel
......
cudnn 8.2.1 cuda11.3_0
.....
keras 2.9.0 pypi_0 pypi
keras-preprocessing 1.1.2 pypi_0 pypi
libclang 14.0.6 pypi_0 pypi
libedit 3.1.20210910 h7f8727e_0
.......
scipy 1.7.3 pypi_0 pypi
setuptools 65.5.0 py38h06a4308_0
six 1.16.0 pypi_0 pypi
sqlite 3.33.0 h62c20be_0
tensorboard 2.9.1 pypi_0 pypi
tensorboard-data-server 0.6.1 pypi_0 pypi
tensorboard-plugin-wit 1.8.1 pypi_0 pypi
tensorflow 2.9.0 pypi_0 pypi
tensorflow-datasets 4.6.0 pypi_0 pypi
tensorflow-estimator 2.9.0 pypi_0 pypi
tensorflow-io-gcs-filesystem 0.28.0 pypi_0 pypi
tensorflow-metadata 1.11.0 pypi_0 pypi
termcolor 2.1.1 pypi_0 pypi
tk 8.6.12 h1ccaba5_0
I faced a similar problem while using VS Code. I had created a virtual environment using venv, but when I selected that environment, I wasn't able to import any libraries even though I had installed all the required ones.
I simply deleted the environment and created a new one using -
conda create --prefix ./env pandas numpy ... in the terminal/command prompt. I then restarted VS Code and selected this particular environment. That fixed the issue. The python version and the library versions need to be in sync with each other to work properly. Hope this works for you too.
Edit:
I was again facing the same problem when I created a new environment. I then selected the python environment where I had installed the Tensorflow library from the top right corner in Jupyter notebook (underlined red). That solved the issue!
I have created a Python 3.7 conda virtual environment and installed the following packages using this command:
conda install pytorch torchvision torchaudio cudatoolkit=11.3 matplotlib scipy opencv -c pytorch
They install fine, but then when I come to run my program I get the following error which suggests that a CUDA enabled device is not found:
raise RuntimeError('Attempting to deserialize object on a CUDA '
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.
I have an NVIDIA RTX 3060ti GPU, which as far as I am aware is cuda enabled, but whenever I go into the Python interactive shell within my conda environment I get False when evaluating torch.cuda.is_available() suggesting that perhaps CUDA is not installed properly or is not found.
When I then perform a conda list to view my installed packages:
# packages in environment at /home/user/anaconda3/envs/FGVC:
#
# Name Version Build Channel
_libgcc_mutex 0.1 main
_openmp_mutex 4.5 1_gnu
blas 1.0 mkl
brotli 1.0.9 he6710b0_2
bzip2 1.0.8 h7b6447c_0
ca-certificates 2021.10.26 h06a4308_2
cairo 1.16.0 hf32fb01_1
certifi 2021.10.8 py37h06a4308_2
cpuonly 1.0 0 pytorch
cudatoolkit 11.3.1 h2bc3f7f_2
cycler 0.11.0 pyhd3eb1b0_0
dbus 1.13.18 hb2f20db_0
expat 2.4.4 h295c915_0
ffmpeg 4.0 hcdf2ecd_0
fontconfig 2.13.1 h6c09931_0
fonttools 4.25.0 pyhd3eb1b0_0
freeglut 3.0.0 hf484d3e_5
freetype 2.11.0 h70c0345_0
giflib 5.2.1 h7b6447c_0
glib 2.69.1 h4ff587b_1
graphite2 1.3.14 h23475e2_0
gst-plugins-base 1.14.0 h8213a91_2
gstreamer 1.14.0 h28cd5cc_2
harfbuzz 1.8.8 hffaf4a1_0
hdf5 1.10.2 hba1933b_1
icu 58.2 he6710b0_3
imageio 2.16.0 pypi_0 pypi
imageio-ffmpeg 0.4.5 pypi_0 pypi
imutils 0.5.4 pypi_0 pypi
intel-openmp 2021.4.0 h06a4308_3561
jasper 2.0.14 hd8c5072_2
jpeg 9d h7f8727e_0
kiwisolver 1.3.2 py37h295c915_0
lcms2 2.12 h3be6417_0
ld_impl_linux-64 2.35.1 h7274673_9
libffi 3.3 he6710b0_2
libgcc-ng 9.3.0 h5101ec6_17
libgfortran-ng 7.5.0 ha8ba4b0_17
libgfortran4 7.5.0 ha8ba4b0_17
libglu 9.0.0 hf484d3e_1
libgomp 9.3.0 h5101ec6_17
libopencv 3.4.2 hb342d67_1
libopus 1.3.1 h7b6447c_0
libpng 1.6.37 hbc83047_0
libstdcxx-ng 9.3.0 hd4cf53a_17
libtiff 4.2.0 h85742a9_0
libuuid 1.0.3 h7f8727e_2
libuv 1.40.0 h7b6447c_0
libvpx 1.7.0 h439df22_0
libwebp 1.2.0 h89dd481_0
libwebp-base 1.2.0 h27cfd23_0
libxcb 1.14 h7b6447c_0
libxml2 2.9.12 h03d6c58_0
lz4-c 1.9.3 h295c915_1
matplotlib 3.5.0 py37h06a4308_0
matplotlib-base 3.5.0 py37h3ed280b_0
mkl 2021.4.0 h06a4308_640
mkl-service 2.4.0 py37h7f8727e_0
mkl_fft 1.3.1 py37hd3c417c_0
mkl_random 1.2.2 py37h51133e4_0
munkres 1.1.4 py_0
ncurses 6.3 h7f8727e_2
networkx 2.6.3 pypi_0 pypi
ninja 1.10.2 py37hd09550d_3
numpy 1.21.2 py37h20f2e39_0
numpy-base 1.21.2 py37h79a1101_0
olefile 0.46 py37_0
opencv 3.4.2 py37h6fd60c2_1
openssl 1.1.1m h7f8727e_0
packaging 21.3 pyhd3eb1b0_0
pcre 8.45 h295c915_0
pillow 8.4.0 py37h5aabda8_0
pip 21.2.2 py37h06a4308_0
pixman 0.40.0 h7f8727e_1
py-opencv 3.4.2 py37hb342d67_1
pyparsing 3.0.4 pyhd3eb1b0_0
pyqt 5.9.2 py37h05f1152_2
python 3.7.11 h12debd9_0
python-dateutil 2.8.2 pyhd3eb1b0_0
pytorch 1.7.0 py3.7_cpu_0 [cpuonly] pytorch
pywavelets 1.2.0 pypi_0 pypi
qt 5.9.7 h5867ecd_1
readline 8.1.2 h7f8727e_1
scikit-image 0.19.1 pypi_0 pypi
scipy 1.7.3 py37hc147768_0
setuptools 58.0.4 py37h06a4308_0
sip 4.19.8 py37hf484d3e_0
six 1.16.0 pyhd3eb1b0_1
sqlite 3.37.2 hc218d9a_0
tifffile 2021.11.2 pypi_0 pypi
tk 8.6.11 h1ccaba5_0
torchaudio 0.7.0 py37 pytorch
torchvision 0.8.1 py37_cpu [cpuonly] pytorch
tornado 6.1 py37h27cfd23_0
typing_extensions 3.10.0.2 pyh06a4308_0
wheel 0.37.1 pyhd3eb1b0_0
xz 5.2.5 h7b6447c_0
zlib 1.2.11 h7f8727e_4
zstd 1.4.9 haebb681_0
There seems to be a lot of things saying cpuonly, but I am not sure how they came about, since I did not install them.
I am running Ubuntu version 20.04.4 LTS
I ran into a similar problem when I tried to install Pytorch with CUDA 11.1. Although the anaconda site explicitly lists a pre-built version of Pytorch with CUDA 11.1 is available, conda still tries to install the cpu-only version. After a lot of trial-and-fail, I realize that the packages torchvision torchaudio are the root cause of the problem. So installing just PyTorch would fix this:
conda install pytorch cudatoolkit=11.1 -c pytorch -c nvidia
You can ask conda to install a specific build of your required package.pytorch builds supporting cuda have the phrase cuda somewhere in their build string, so you can ask conda to match that spec. For more information, have a look at conda's package match spec.
$ conda install pytorch=*=*cuda* cudatoolkit -c pytorch
I believe I had the following things wrong that prevented me from using Cuda. Despite having cuda installed the nvcc --version command indicated that Cuda was not installed and so what I did was add it to the path using this answer.
Despite doing that and deleting my original conda environment and using the conda install pytorch torchvision torchaudio cudatoolkit=11.3 matplotlib scipy opencv -c pytorch command again I still got False when evaluating torch.cuda.is_available().
I then used this command conda install pytorch torchvision torchaudio cudatoolkit=10.2 matplotlib scipy opencv -c pytorch changing cudatoolkit from verison 11.3 to version 10.2 and then it worked!
Now torch.cuda.is_available() evaluates to True
Unfortunately, Cuda version 10.2 was incompatible with my RTX 3060 gpu (and I'm assuming it is not compatible with all RTX 3000 cards). Cuda version 11.0 was giving me errors and Cuda version 11.3 only installs the CPU only versions for some reason. Cuda version 11.1 worked perfectly though!
This is the command I used to get it to work in the end:
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
If there is nothing wrong with your nvidia driver setup, maybe you are missing nvidia channel from installation arguments. The pytorch documentation helped me generate this command that eventually solved my problem:
conda install pytorch torchvision torchaudio pytorch-cuda=11.6 -c pytorch -c nvidia
Installing jupyter inside conda's virtual environment solve my issue. I was having the same issue, even pytorch with cuda is installed and !nvidia-smi showing GPU , but while trying to access jupyter notebook , it was showing only cpu.
While I was trying from command line torch is finding CUDA but from jupyter is not showing, So I just pip install jupyter on virtual environment of conda and after that problem is solved .
Use the exact script from the Pytorch website works for me:
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=10.2 -c pytorch
But if I use
conda install pytorch==1.12.1 torchvision==0.13.1 cudatoolkit=10.2 -c pytorch
no installing torchaudio, it will install cpu versions of pytorch and torchvision. I found it interesting and don't know why.
I'm trying to install tensorflow-io to work with flac audio files
For that I use this command pip install -q tensorflow-io
But I got this Error:
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
kubernetes 10.1.0 requires pyyaml~=3.12, but you have pyyaml 5.3.1 which is incompatible.
jupyterlab-git 0.10.0 requires nbdime<2.0.0,>=1.1.0, but you have nbdime 2.0.0 which is incompatible.
google-cloud-pubsub 1.4.3 requires google-api-core[grpc]<1.17.0,>=1.14.0, but you have google-api-core 1.23.0 which is incompatible.
earthengine-api 0.1.244 requires google-api-python-client>=1.12.1, but you have google-api-python-client 1.8.0 which is incompatible.
bokeh 2.2.3 requires tornado>=5.1, but you have tornado 5.0.2 which is incompatible.
astroid 2.3.3 requires wrapt==1.11.*, but you have wrapt 1.12.1 which is incompatible.
aiobotocore 1.1.2 requires botocore<1.17.45,>=1.17.44, but you have botocore 1.19.31 which is incompatible.
How to install tensorflow-io on kaggle notebook
I think it's only a warning. I got the same somedays back when I did
!pip install tensorflow-io
It got installed successfully and I was able to train also.
I need to use Tensorflow and Tensorflow_Probability. After installing it by these commands: conda install tensorflow-probability or pip install --upgrade tensorflow-probability , I ran it in the notebook:
import tensorflow_probability as tfp
but it returns this error:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-8-41494c8c96ff> in <module>
----> 1 import tensorflow_probability as tfp
ModuleNotFoundError: No module named 'tensorflow_probability'.
The results of
pip list
is as below (related parts):
tblib 1.3.2
tensorboard 1.13.1
tensorflow 1.13.1
tensorflow-estimator 1.13.0
tensorflow-probability 0.7.0
termcolor 1.1.0
terminado 0.8.1
testpath 0.4.2
tfp-nightly 0.8.0.dev20190708
Theano 1.0.4
toolz 0.9.0
Can anyone help me to solve this problem (I am using Win 10)?
Your versions are correct and your command is correct too.
Seems like inconsistency in other module is causing this.
run the following commands and try again:
pip install -U dm-sonnet==1.23
pip install --upgrade tfp-nightly
References:
https://github.com/deepmind/graph_nets/issues/3
https://github.com/tensorflow/probability/issues/103
tensorflow-probability 0.7.0
is not compatible with:
tensorflow 1.13.1
check the tensoflow-probability version release page https://github.com/tensorflow/probability/releases
Correct solution will be either to upgrade tensorflow to 1.14.0 or downgrade tensorflow-probability to 0.6.0
pip install -U tensorflow-probability==0.6.0
As the previous answer, you have to find a version compatible with your TensorFlow version through this page: https://github.com/tensorflow/probability/releases
Getting the following stack trace from line:
zipline/zipline/__init__.py", line 17, in <module>
import numpy as np
ImportError: No module named 'numpy'
however, when I check pip list
pip list | grep numpy
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
numpy 1.16.6
This all occurs after I clone into the Quantopian/Zipline Github Repo.
I opened an issue on github, after this edit I'll search SO for anything obvious I missed.
Environment
WSL Ubunut Subsystem
Pyhon 3.5.5
Bitness: 64
installed dependencies via
sudo apt-get install libatlas-base-dev python-dev gfortran pkg-config libfreetype6-dev
Pip list
alembic 1.4.2
asn1crypto 0.24.0
bcolz 0.12.1
Bottleneck 1.3.2
certifi 2019.11.28
chardet 3.0.4
click 7.1.1
contextlib2 0.6.0.post1
cycler 0.10.0
cyordereddict 1.0.0
Cython 0.29.15
decorator 4.4.2
empyrical 0.5.3
enum34 1.1.6
funcsigs 1.0.2
idna 2.6
intervaltree 3.0.2
ipaddress 1.0.17
itable 0.0.1
keyring 10.6.0
Logbook 1.5.3
lru-dict 1.1.6
lxml 4.5.0
Mako 1.1.2
MarkupSafe 1.1.1
matplotlib 2.2.4
mercurial 4.5.3
mock 3.0.5
multipledispatch 0.6.0
networkx 1.11
numexpr 2.7.1
numpy 1.16.6
pandas 0.22.0
pandas-datareader 0.8.1
patsy 0.5.1
pinkfish 0.5.1
pip 19.3.1
pycrypto 2.6.1
pygobject 3.26.1
python-dateutil 2.8.1
python-editor 1.0.4
pytz 2019.3
pyxdg 0.25
requests 2.22.0
requests-file 1.4.3
scipy 1.2.2
SecretStorage 2.3.1
setuptools 39.0.1
six 1.14.0
sortedcontainers 2.1.0
SQLAlchemy 1.3.15
statsmodels 0.11.0
tables 3.5.2
toolz 0.10.0
trading-calendars 1.11.5
urllib3 1.25.7
wheel 0.30.0
zipline 1.3.0
WARNING: You are using pip version 19.3.1; however, version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Update
running as a script, sudo python test.py returns
File "test.py", line 1, in <module>
import zipline
File "../zipline/zipline/__init__.py", line 29, in <module>
from .utils.run_algo import run_algorithm
File "../zipline/zipline/utils/run_algo.py", line 17, in <module>
from zipline.data import bundles
File "../zipline/zipline/data/bundles/__init__.py", line 2, in <module>
from . import quandl # noqa
File "../zipline/zipline/data/bundles/quandl.py", line 17, in <module>
from . import core as bundles
File "../zipline/zipline/data/bundles/core.py", line 14, in <module>
from ..adjustments import SQLiteAdjustmentReader, SQLiteAdjustmentWriter
File "../zipline/zipline/data/adjustments.py", line 24, in <module>
from ._adjustments import load_adjustments_from_sqlite
ImportError: No module named _adjustments
The issue arose due to the presence of multiple versions of python. Using the python -m pip install <packages> command inside of the zipline/zipline repo, I was able to successful execute import zipline inside a python shell