I am learning to develop with PyTorch as well as LibTorch. I have the following line in my ~/.bashrc for dynamic linking of libtorch libraries:
# libtorch linking path
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/user/.dev_libraries/libtorch/lib/
However, when this path is in LD_LIBRARY_PATH, importing torch in Python reports segmentation fault:
user#host:~$ $LD_LIBRARY_PATH
bash: /home/user/packages/embree-2.16.0.x86_64.linux/lib:/home/user/packages/embree-2.16.0.x86_64.linux/lib::/usr/local/lib/:/usr/local/cuda-11.1/lib64:/usr/local/lib/:/usr/local/cuda-11.1/lib64:/home/user/.dev_libraries/libtorch-cpu/libtorch/lib/: No such file or directory
user#host:~$ python
Python 3.8.10 (default, Jun 2 2021, 10:49:15)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Segmentation fault (core dumped)
user#host:~$
As soon as I remove that path from the environment variable LD_LIBRARY_PATH, torch can be correctly imported in Python.
I am guessing the cause is that some shared libraries of PyTorch having the same names as the ones in LibTorch. Does this mean PyTorch and LibTorch cannot be installed simultaneously, or is my environment setting incorrect? I'd prefer not to reset LD_LIBRARY_PATH every time I switch between the two.
System specs:
Ubuntu 20.04 + CUDA 11.1 + python 3.8.10 + GCC 9.3.0
pytorch 1.9.0+cu111
libtorch is downloaded from here: https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip
I faced the same problem too.
You can type
import torch
print(torch.__version__)
to see the version of torch, and use the same version of libtorch, that would solve the problem probably.
Related
I uninstalled tensorflow with:
pip uninstall tensorflow
it was successful and when I run it again, I receive this message:
Skipping tensorflow as it is not installed.
The issue is that when I import tensorflow inside python via:
python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
2022-05-27 09:35:22.981575: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
2022-05-27 09:35:22.981872: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
>>> tensorflow.__version__
'1.15.0'
>>>
Do there is tensorflow installed and I could not uninstall it. How can I uninstall it completely? I want to install tensorflow==1.14 instead of 1.15.
I can install tensorflow==1.14.0 via:
pip install tensorflow==1.14.0
but when I run python, it's using tensorflow==1.15 instead of 1.14.0
If you run "pip list", do you see TF listed still?
Are you running Python with your code in a VENV? Curious if TensorFlow could be installed in main Python yet removed from VENV (though I saw your response to comment above).
Maybe go into Python's site-packages dir and check if TF package folder exists. If on Windows, maybe Python is installed in your Users directory, this TF the same. It can definitely get confusing.
Other folks mentioned to uninstall using "...-{cpu|gpu}".
I found this SO discussion about similar issue that may help.
Link
Please keep us updated on findings.
Because of the incompatibility between the Apple's new M1 chip and TensorFlow in Python, I followed some online guides to create an environment under Miniforge3 (so that we can run the python in the arm64 instead of the x86_64 one? I don't fully understand the tricks here.).
Following the tutorial (at https://medium.com/codex/installing-tensorflow-on-m1-macs-958767a7a4b3), I created an environment named tf and successfully installed tensorflow. I checked that the modules are installed inside the miniforge3 folder:
(tf) pokfung#pn-204-145 ~ % which python
/Users/pokfung/miniforge3/envs/tf/bin/python
(tf) pokfung#pn-204-145 ~ % python
Python 3.8.10 | packaged by conda-forge | (default, May 11 2021, 06:27:18)
[Clang 11.1.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy, tensorflow
>>> print(numpy.__file__)
/Users/pokfung/miniforge3/envs/tf/lib/python3.8/site-packages/numpy/__init__.py
>>> print(tensorflow.__file__)
/Users/pokfung/miniforge3/envs/tf/lib/python3.8/site-packages/tensorflow/__init__.py
However, when I initiate the Jupyter notebook by (tf) pokfung#pn-204-145 ~ % jupyter notebook, I found that the notebook was not loading modules from the above directories:
import numpy
print(numpy.__file__)
# Output of the print statement is:
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/__init__.py
I wonder how I shall configure the Jupyter notebook so that it can correctly run in the tf conda environment.
Jupyter runs a kernel in the background that in your case supports Python, but it chooses the kernel from your main installation not the virtual environment you just installed. You can tell Jupyter which kernel to use - Have you tried that?
I have installed tensorflow following the https://www.tensorflow.org/install/pip
steps. I installed it through Anaconda.
I also tried using a virtual environment without using anaconda as this page provided (please check image). It also gave the same error.
Following images shows the versions I have installed and its given error.
I am using,
Ubuntu 18.04.1 LTS
x86_64
Processor: Intel(R) Core(TM) 2 Duo CPU T5870 # 2.00 GHz 2.00 GHz
Installed memory (RAM): 2.00 GB
Version:
Error:
I tried to overcome this but, I couldn't find a solution. I am new to tensorflow and trying to install and learn it. Please help me to solve this.
Thanks for the earlier answers.
I was facing the exact problem for SSE4.2 instruction.
I installed tensorflow 1.5 instead of 1.12 and it is working.
Error message on my system
The TensorFlow library was compiled to use SSE4.2 instructions, but these aren't available on your machine.
Aborted (core dumped)
Solution
Here is what I did:
Please run these inside virtual environment:
pip uninstall tensorflow
pip install tensorflow==1.5
You can replace 1.5 with any version that suits your machine.
Try importing it again it should run now
Your CPU is too old for running TensorFlow as it lacks the required Instruction set. Starting with TensorFlow 1.6, binaries use AVX instructions which may not run on older CPUs. - According to Tensorflow.
You have 2 possible solutions:
Using cloud/web based solution, e.g. Google Colab
Upgrade your Machine to a modern build
I have the same error on the laptop HP ProBook 4720s:
python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2019-04-16 17:50:25.829023: F tensorflow/core/platform/cpu_feature_guard.cc:37] The TensorFlow library was compiled to use AVX instructions, but these aren't available on your machine.
Aborted (core dumped)
But I installed TensorFlow via Anaconda conda installation:
conda install tensorflow # install TensorFlow for CPU
conda activate DL3 # activate virtual environment DL3
python
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> print(tf.__version__)
1.13.1
>>> exit()
I'm running an Anaconda virenv that has successfully installed OpenCV ver.3.4.1. From the python prompt I can import cv2 and can confirm it's version per the command line below:
Python 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 11:07:29)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.4.1'
However, in VSCode I run the following simple program and get an error:
import numpy as numpy
import argparse
import cv2
pass
The error is:
Traceback (most recent call last):
File "detect_faces.py", line 3, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
I don't understand why the command line import works, but the program from VSCode fails to import the same package.
There are multiple SO Q&A on this topic but they are all incredibly time/date sensitive and platform specific -- most deal with the situation where the package itself isn't recognized anywhere. The closest question is this one which is from 2015 and deals with the Android platform. Any thoughts?
Update
The version installed should be 3.5.5, but I noticed that in the command prompt launched from anaconda it's shown as Python 3.5.5 :: Anaconda, Inc. while the version shown within VSCode is Python 3.6.5 :: Anaconda, Inc.. When I look at the available env in VSCode it shows some 2.7s and several 3.6 versions - including the one I'm using which is 3.6.5.
I've just done a new install of a fresh Python 3.6 env and noticed that the command prompt reports Python 3.6.6 while the output from a sys check reports Python 3.6.5 -- again, both have the same executable path.
Although I was unable to replicate this same error, I did determine that it had to do with the installation of numpy. For whatever reason, it originally installed and downgraded the Python version within the venv. Then later when upgrading python it created a mismatch. The fix was to recreate the venv with a pip install of all three packages in the same command line. When installing all three at once the packages all reconcile - - I don't know if there was another variable - I couldn't recreate the original error.
I use sudo pip install tensorflow-1.7.0rc0-cp27-cp27mu-manylinux1_x86_64.whl in centos7,python version is 2.7.14
I get successfully installed tensorflow,but when I run import tensorflow as tf,I get a error:No module named tensorflow
what should I do? thanks!
As mentioned in the comments you best method for installing pyhton packages is to use a virtual environment. For a simple way to do this you can install Minicaonda for linux x86 using the following command:
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash ./Miniconda3-latest-Linux-x86_64.sh
Then it is worth reading the instructions on using conda, to set up a virtual environment called tensorflow. But the basic command should be:
conda create -n tensorflow python=3.6 tensorflow
provided you want to use tensorflow with python3.6. Then activate your tensorflow conda environment:
source activate tensorflow
and you should be able to import tensorflow without issue.
(tensorflow) user#machine:~$ python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>>