Numpy related Error while running a docker container - python-3.x

I composed a docker image file that gets built successfully.
However, when I run a container with that image, it produces the following numpy error and exits.
Any idea how this could be corrected?
ERROR:
Traceback (most recent call last):
File "/opt/venv/lib/python3.9/site-packages/numpy/core/__init__.py", line 22, in <module>
from . import multiarray
File "/opt/venv/lib/python3.9/site-packages/numpy/core/multiarray.py", line 12, in <module>
from . import overrides
File "/opt/venv/lib/python3.9/site-packages/numpy/core/overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /opt/venv/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-x86_64-linux-gnu.so)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/app/./MetReTrim", line 14, in <module>
import matplotlib.pyplot as plt
File "/opt/venv/lib/python3.9/site-packages/matplotlib/__init__.py", line 107, in <module>
from . import _api, cbook, docstring, rcsetup
File "/opt/venv/lib/python3.9/site-packages/matplotlib/cbook/__init__.py", line 28, in <module>
import numpy as np
File "/opt/venv/lib/python3.9/site-packages/numpy/__init__.py", line 150, in <module>
from . import core
File "/opt/venv/lib/python3.9/site-packages/numpy/core/__init__.py", line 48, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.9 from "/opt/venv/bin/python"
* The NumPy version is: "1.21.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /opt/venv/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-x86_64-linux-gnu.so)

Did you install numpy outside of docker, and copied the venv?
If so, C extensions were compiled for your host (which, according to the error, is not Linux)
You'll need to install numpy into the container itself

Related

'Invalid syntax' error when importing torch (Linux)

I'm trying to install torch under miniconda and simple import torch gives me the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/vol/tcm17/username/miniconda3/lib/python3.8/site-packages/torch/__init__.py", line 779, in <module>
from .serialization import save, load
File "/vol/tcm17/username/miniconda3/lib/python3.8/site-packages/torch/serialization.py", line 18, in <module>
from typing_extensions import TypeAlias
File "/home/username/.local/lib/python3.8/site-packages/typing_extensions.py", line 880
if stripped_args
Interestingly, if I repeat import torch again the error message changes:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/vol/tcm17/username/miniconda3/lib/python3.8/site-packages/torch/__init__.py", line 249, in <module>
for name in dir(_C):
NameError: name '_C' is not defined
I'm not using notebooks, python version is 3.8.16, pytorch version is 1.13.1. Miniconda is installed in a local folder (it's a university server so I can only do it like this due to disk space restrictions), the server runs on Ubuntu.
What could possibly be the problem?
The only recommendation I found for similar problems is to install Cython but it didn't help.
Downgraded to python 3.6 and this somehow solved the problem.

Why does a DLL error appear when importing tensorflow?

I recently got a new 64-bit windows 10 and installed pycharm. The pycharm I am using is Python 3.8.
When I installed tensorflow by running the command line, it worked fine. However, when I imported on my pycharm file (i.e. import tensorflow as tf), it produced an error as such:
Traceback (most recent call last):
File "C:\Users\leode\anaconda3\envs\Science Fair\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/leode/PycharmProjects/Science Fair/project.py", line 1, in <module>
import tensorflow as tf
File "C:\Users\leode\anaconda3\envs\Science Fair\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\leode\anaconda3\envs\Science Fair\lib\site-packages\tensorflow\python\__init__.py", line 40, in <module>
from tensorflow.python.eager import context
File "C:\Users\leode\anaconda3\envs\Science Fair\lib\site-packages\tensorflow\python\eager\context.py", line 35, in <module>
from tensorflow.python import pywrap_tfe
File "C:\Users\leode\anaconda3\envs\Science Fair\lib\site-packages\tensorflow\python\pywrap_tfe.py", line 28, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\leode\anaconda3\envs\Science Fair\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\leode\anaconda3\envs\Science Fair\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.
Failed to load the native TensorFlow runtime.
However when I import tensorboard_plugin_wit:
import tensorboard_plugin_wit
It works fine.
What went wrong? If any of you need any further clarification, please comment- I'm not much of an expert on handling computers so I will do my best to answer:)
I figured out what the problem was. Unlike many third-party modules in python, installing tensorflow requires more than simply pip install . The way I installed tensorflow was by creating and activating a conda environment. For more information on how to install tensorflow via Pycharm, here is a helpful Youtube video: https://www.youtube.com/watch?v=5Ym-dOS9ssA&t=327s

Failed to import tensorflow

File "C:\Users\deepz\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\deepz\anaconda3\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\deepz\anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 40, in <module>
from tensorflow.python.eager import context
File "C:\Users\deepz\anaconda3\lib\site-packages\tensorflow\python\eager\context.py", line 35, in <module>
from tensorflow.python import pywrap_tfe
File "C:\Users\deepz\anaconda3\lib\site-packages\tensorflow\python\pywrap_tfe.py", line 28, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\deepz\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\deepz\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors
on importing TensorFlow as tf
I am getting this error please can someone help me to solve this problem.
system HP 245 G5 and operating system windows 10 2004 version
If you have Anaconda installed I recommend you use Conda to install tensorflow into a new environment. Reason is Conda installs tensorflow and the required Cuda Toolkit and the proper version of cuDNN. Pip does not install these and you have to download them seperately, unzip and store them in directories. You also have to adjust you environment variable to point to these directories.

unable to run a python file because of Module not found error despite sourcing the pythonpath

I have been trying to run a python file using rosrun command but unfortunately I am having this module not found error because of a package named rospkg. Until a day before yesterday, it was all working fine but yesterday, ubuntu18.04 has got some updates out of which an update for ubuntu base was also present, since that update I am having this error.
I have tried to check whether I have installed the respective python-rospkg and its says I already have the latest version. I have also using
echo $PYTHONPATH
to check the sourced paths and they are sourced correct, I am not sure whats causing this error.
the error is as follows
Traceback (most recent call last
File
"/home/microbot/catkin_ws/src/spider/spider_control/control.py",
line 5, in <module>
import roslib
File "/opt/ros/melodic/lib/python2.7/dist-
packages/roslib/__init__.py", line 50, in <module>
from roslib.launcher import load_manifest
File "/opt/ros/melodic/lib/python2.7/dist-
packages/roslib/launcher.py", line 42, in <module>
import rospkg
ModuleNotFoundError: No module named 'rospkg'
The shebang for my is as follows,
#!/usr/bin/python3
When i try to run the file by changing the shebang to
#!/usr/bin/python2.7
I get the following error
Traceback (most recent call last):
File
"/home/microbot/catkin_ws/src/spider/spider_control/control.py",
line 3, in <module>
import tensorflow as tf
ImportError: No module named tensorflow
I have installed tensorflow version 1.14 using pip installation. Can anyone please help me solving this error. Thanks in advance
edit:
I have manually tried to set the python path to /usr/lib/python2.7/dist-packages as when I tried to install python-rospkg, it says the its already instaled in that location. Doing that I am having error importing tensorflow and the error is
`Traceback (most recent call last):
File
"/home/microbot/catkin_ws/src/spider/spider_control/control.py", line
3, in <module>
import tensorflow as tf
File "/home/microbot/.local/lib/python3.6/site-
packages/tensorflow/__init__.py", line 22, in <module>
import inspect as _inspect
File "/usr/lib/python3.6/inspect.py", line 41, in <module>
import linecache
File "/usr/lib/python3.6/linecache.py", line 11, in <module>
import tokenize
File "/usr/lib/python3.6/tokenize.py", line 33, in <module>
import re
File "/usr/lib/python3.6/re.py", line 142, in <module>
class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'
Error in sys.excepthook:`

Matplotlib and numpy import don't work after pycharm 2019 optimize imports

I used Pycharm 2019.1's import optimization on a full project and now the imports for matplotlib and numpy don't work.
Here is the full error code:
Traceback (most recent call last):
File "C:/Users/LENOVO/PycharmProjects/CSinternal/LearnIt.py", line 8, in <module>
import matplotlib
File "C:\Users\LENOVO\PycharmProjects\CSinternal\venv\lib\site-packages\matplotlib\__init__.py", line 139, in <module>
from . import cbook, rcsetup
File "C:\Users\LENOVO\PycharmProjects\CSinternal\venv\lib\site-packages\matplotlib\cbook\__init__.py", line 31, in <module>
import numpy as np
File "C:\Users\LENOVO\PycharmProjects\CSinternal\venv\lib\site-packages\numpy\__init__.py", line 141, in <module>
from . import core
File "C:\Users\LENOVO\PycharmProjects\CSinternal\venv\lib\site-packages\numpy\core\__init__.py", line 37, in <module>
from . import multiarray
File "C:\Users\LENOVO\PycharmProjects\CSinternal\venv\lib\site-packages\numpy\core\multiarray.py", line 20, in <module>
from . import overrides
File "C:\Users\LENOVO\PycharmProjects\CSinternal\venv\lib\site-packages\numpy\core\overrides.py", line 45, in <module>
""")
RuntimeError: implement_array_function method already has a docstring
I'm new here and honestly don't know what this ( RuntimeError: implement_array_function method already has a docstring) means.
Any help is much appreciated.
I had the same issue and the solution for me appeared when I realized that I had imported torch as two different names in different files in the same project. By renaming them I got rid of the error. I suspect you might have a similar issue. Try running the code in a new project without any other files in the same project.

Resources