PyTorch 1.12 on Mac Monterey - python

I cannot use PyTorch 1.12.1 on macOS 12.6 Monterey with M1 chip.
Tried to install and run from Python 3.8, 3.9 and 3.10 with the same result.
I think that PyTorch was working before I updated macOS to Monterey. And the Rust bindings, tch-rs are still working.
Here is my install and the error messages I get when trying to run.
Install
brew install libtorch
python3.9 -m venv venv39
source venv39/bin/activate
pip3 install torch torchvision torchaudio
Error message
python
Python 3.9.14 (main, Sep 6 2022, 23:16:16)
[Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "~/Documents/install/Modern_Computer_Vision/venv39/lib/python3.9/site-packages/torch/__init__.py", line 202, in <module>
from torch._C import * # noqa: F403
ImportError: dlopen(~/Documents/install/Modern_Computer_Vision/venv39/lib/python3.9/site-packages/torch/_C.cpython-39-darwin.so, 0x0002): Symbol not found: (__ZN4c10d11debug_levelEv)
Referenced from: '#/Documents/install/Modern_Computer_Vision/venv39/lib/python3.9/site-packages/torch/lib/libtorch_python.dylib'
Expected in: '/opt/homebrew/Cellar/libtorch/1.12.1/lib/libtorch_cpu.dylib'
Tried using Miniconda
I had almost the same result.
conda create -n conda39 python=3.9 -y
conda activate conda39
conda install pytorch torchvision torchaudio -c pytorch
❯ python
Python 3.9.12 (main, Apr 5 2022, 01:52:34)
[Clang 12.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/sami/miniconda3/lib/python3.9/site-packages/torch/__init__.py", line 202, in <module>
from torch._C import * # noqa: F403
ImportError: dlopen(/Users/sami/miniconda3/lib/python3.9/site-packages/torch/_C.cpython-39-darwin.so, 0x0002): Symbol not found: (__ZN4c10d11debug_levelEv)
Referenced from: '/Users/sami/miniconda3/lib/python3.9/site-packages/torch/lib/libtorch_python.dylib'
Expected in: '/opt/homebrew/Cellar/libtorch/1.12.1/lib/libtorch_cpu.dylib'

I recommend not touching your system python installations for your own projects, instead the recommended way is using conda (see here). The reason is that each conda environment encapsulates a whole separate python installation that does not interfere (and doesn't get interfered with) with any other programs. This is especially important for C/C++ libraries like the ones pytorch is using.

I had similar problem when trying to install PyTorch 1.13.
The PyTorch install instruction was not working, but it was due to a conflict between brew and Miniconda. When I uninstalled Miniconda both stable and nightly pip install worked.
virtualenv -p /opt/homebrew/Cellar/python#3.9/3.9.14/bin/python3.9 pt113
source pt113/bin/activate
pip3 install torch torchvision torchaudio
pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu

Related

ImportError: libhdf5_serial.so.100: Installing opencv-contrib-python package on ARM CPU (Stratodesk OS)

I am trying to install opencv package on Raspberry Pi (Stratodesk OS). the best shot I got so far is through: https://www.piwheels.hostedpi.com/simple
However, after installing
pip install opencv-contrib-python --extra-index-url https://www.piwheels.hostedpi.com/simple
when importing the cv2 in python I get import error message related to libhdf5_serial.so.100:
root#PNAR55:~# python3
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
import cv2
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.5/dist-packages/cv2/init.py", line 3,
in
from .cv2 import *
ImportError: libhdf5_serial.so.100: cannot open shared object file: No
such file or directory
besides, I tried to install opencv-python but without success
pip install opencv-python --extra-index-url https://www.piwheels.hostedpi.com/simple
when importing cv2, I am getting a different ImportError message related to liblapack.so.3
import cv2
Traceback (most recent call last): File "", line
1, in File
"/usr/local/lib/python3.5/dist-packages/cv2/init.py", line 3, in
from .cv2 import * ImportError: liblapack.so.3: cannot open shared object file: No such file or directory
for your information, Stratodesk OS is quite different that Raspbian. I do not have git, cmake, apt-get commands.
if there is a way to overcome the error messages I am getting
This problem is due to an incompatibility between your board and the OpenCV version. If you installed it via pip try pip uninstall opencv-python or pip3 uninstall opencv-python (depending of the python version you need (pip for python2 and pip for python3). After uninstaling is complete, try to search for an older version of opencv and install via pip3 install opencv-python==3.4.6.27 (this is the version that worked for me. I'm almost sure you'll need another one). Also, check this link, and this one!

Conda does not work anymore after installing Jupyter Hub

I've installed jupyter-hub on my machine that was running smoothly with jupyter-lab, conda and python3.6.
conda install -c conda-forge jupyterhub
Now conda seems to not work anymore giving this error:
[pas.datascience_dev#devrmdatasci01 site-packages]$ conda
Traceback (most recent call last):
File "/data/pyconda3/bin/conda", line 12, in <module>
from conda.cli import main
ModuleNotFoundError: No module named 'conda'
Now if i run python, it seems to use python3.7 packaged by conda-forge
[pas.datascience_dev#devrmdatasci01 python3.6]$ python
Python 3.7.3 | packaged by conda-forge | (default, Mar 27 2019, 23:01:00)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
If i go to my python installation path i can see both a directory python3.6 and a directory python3.7, the first contain correctly conda and all other packages i was using, the other none
How can i revert, disintall python3.7 or stop using it and recode all to use the old python3.6 that was working correctly?
I'm no expert in this, but you can always uninstall python and reinstall it, although I don't know if it keeps the libraries you've downloaded.
my suggestion is run pip install conda, although I'm not sure how it works on Linux.

Unable to import xgboost in Python

I have installed xgboost successfully using pip for Python 2.7.16 (I installed this Python version using Homebrew on macOS High Sierra). My problem is that I'm unable to import xgboost in Python, as per the error message below:
mac-128644:~ user$ python
Python 2.7.16 (default, Apr 12 2019, 15:32:52)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import xgboost
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/xgboost/__init__.py", line 11, in <module>
from .core import DMatrix, Booster
File "/usr/local/lib/python2.7/site-packages/xgboost/core.py", line 163, in <module>
_LIB = _load_lib()
File "/usr/local/lib/python2.7/site-packages/xgboost/core.py", line 154, in _load_lib
'Error message(s): {}\n'.format(os_error_list))
xgboost.core.XGBoostError: XGBoost Library (libxgboost.dylib) could not be loaded.
Likely causes:
* OpenMP runtime is not installed (vcomp140.dll or libgomp-1.dll for Windows, libgomp.so for UNIX-like OSes)
* You are running 32-bit Python on a 64-bit OS
Error message(s): ['dlopen(/usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib, 6): Library not loaded: /usr/local/opt/gcc/lib/gcc/8/libgomp.1.dylib\n Referenced from: /usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib\n Reason: no suitable image found. Did find:\n\t/usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib/libgomp.1.dylib: stat() failed with errno=20']
I've made sure that both my Python version and OS are 64-bit, so the problem is definitely not the second "likely cause." I'm also pretty sure I have OpenMP installed: looking up instructions, for my case I would do brew install llvm and the install was successful. I'm also not sure why it can't seem to find /usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib, as I can cd into that directory and see libxgboost.dylib just fine. It looks like later on in the message it did find it, but still throws an error? What exactly is going on here, and what can I do to fix this error?
Install xgboost first:
pip install xgboost
Then use:
brew install libomp
At last:
import xgboost as

How to install MultiNEAT

I am installing MultiNEAT at conda.
conda create -n py35 python=3.5
source activate py35
conda install multineat -c conda-forge
The installation ended normally, but when importing, the following error appears
python
Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 21:41:56)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import MultiNEAT
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/bc/anaconda3/envs/py35/lib/python3.5/sitepackages/MultiNEAT/__init__.py", line 3, in <module>
from ._MultiNEAT import *
ImportError: libboost_system.so.1.67.0: cannot open shared object file: No such file or directory
Please tell me how to resolve
Looks like the shared object packaged for linux is linked to a specific version of libboost (1.67.0), even though the conda dependency only specifies >=1.66. Installing that version from conda-forge seems to be sufficient:
conda install -n py35 -c conda-forge boost=1.67.0 boost-cpp=1.67.0
You may want to pin these versions so future updates don't mess it up. Also, consider dropping an issue on the GitHub.

Tensorflow on OSX: Failed to load the native TensorFlow runtime (No module named pywrap_tensorflow_internal)

I'm trying to install Tensorflow (r1.2) on my MacBook (OSX 10.12.5).
The installation works, but I'm getting errors, when I try to import TF in python.
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
ImportError: No module named pywrap_tensorflow_internal
Failed to load the native TensorFlow runtime.
I'm working in a virtualenv (using virtualenvwrapper) with up-tp-date packages
python 2.7.10
pip 9.0.1
numpy 1.13.1
wheel 0.29.0
six 1.10.0
I tried to install the default pip package (no GPU support) using pip install tensorflow, first.
Afterwards I also tried to install tensorflow from source following the installation tutorial, without CUDA support (configure script said No CUDA support will be enabled for TensorFlow). Building and installing reported no errors, but I got the same error when I tried to import tensorflow.
Related questions/answers pointed out problems with CUDA or missing Windows dll files, which do not seem to fit my problem.
Any help is welcome. Thanks in advance.
I have the same problem.i did this
First
pip uninstall tensorflow
Download this tensorflow wheel file
Now install this using(in same Directory)
pip install tensorflow-1.6.0-cp36-cp36m-win_amd64.whl
My answer is same to yours.
I deleted the tensorflow with "rm -r ~/tensorflow ",
and finally it working when I have reinstalled it
The detail is here:https://www.tensorflow.org/install/install_mac#CommonInstallationProblems

Categories

Resources