ModuleNotFoundError: No module named 'flask_restful' - docker

I've been trying this for awhile now with no luck. Making a basic api but running into some trouble with the flask_restful module. This is my code:
import markdown
import os
import shelve
from flask import Flask, g
from flask_restful import Resource, Api, reqparse
app = Flask(__name)
#app.route("/")
def index():
with open(os.path.dirname(app.root_path) +
'/README.md', 'r') as markdown_file:
content = markdown_file.read()
return markdown.markdown(content)
This is my requirements.txt:
docker==3.4.1
docker-compose==1.22.0
docker-pycreds==0.3.0
dockerpty==0.4.1
docopt==0.6.2
Flask==1.0.2
Flask-RESTful==0.3.6
requests==2.18.4
urllib3==1.22
websocket-client==0.48.0
This is what I get as an error when running docker-compose up:
Starting python-rest_device-registry_1 ... done
Attaching to python-rest_device-registry_1
device-registry_1 | Traceback (most recent call last):
device-registry_1 | File "./run.py", line 1, in <module>
device-registry_1 | from device_registry import app
device-registry_1 | File "/usr/src/app/device_registry/__init__.py", line 6,
in <module>
device-registry_1 | from flask_restful import Resource, Api, reqparse
device-registry_1 | ModuleNotFoundError: No module named 'flask_restful'
python-rest_device-registry_1 exited with code 1
My docker file is this:
FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "./run.py" ]
What am I doing wrong here? I pip installed Flask and flask_restful but I'm lost for word on what's going on.

It does not look like you are using flask_restful in the code you are showing here. You are just importing it. It might be possible that you started out with just some flask code, which imports ok, then added flask-restful to your requirements file but docker in unaware of it and it has a cached version of that part of the container.
Try to decouple your problem, start by running your python sample outside docker, in a plain old virtualenv and make sure that starts. Then mess look into how docker is installing or not your newly added requirements.

Related

snips-nlu not getting installed on docker

Issue:
I am installing snips in docker with step 1 given in To Reproduce section. I am ending with No module named 'distutils.msvccompiler' error. I am running everything on Linux based system. is there alternative way to install snips-nlu in docker?
To Reproduce
Created installSnips.sh (following) file for installing rust, rust setup tool
pip3 install numpy
pip3 install scipy
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
pip3 install setuptools-rust
source ~/.cargo/env
pip3 install snips-nlu
while running installSnips.sh pip3 install snip-nlu enter in following error
Building wheel for scikit-learn (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [26 lines of output]
Partial import of sklearn during the build process.
/tmp/pip-install-h9opcxf9/scikit-learn_fc42ebd0e5804549ad6f611dced79620/setup.py:123: DeprecationWarning:
`numpy.distutils` is deprecated since NumPy 1.23.0, as a result
of the deprecation of `distutils` itself. It will be removed for
Python >= 3.12. For older Python versions it will remain present.
It is recommended to use `setuptools < 60.0` for those Python versions.
For more details, see:
https://numpy.org/devdocs/reference/distutils_status_migration.html
from numpy.distutils.command.build_ext import build_ext # noqa
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-h9opcxf9/scikit-learn_fc42ebd0e5804549ad6f611dced79620/setup.py", line 303, in <module>
setup_package()
File "/tmp/pip-install-h9opcxf9/scikit-learn_fc42ebd0e5804549ad6f611dced79620/setup.py", line 295, in setup_package
from numpy.distutils.core import setup
File "/home/drjslab/.local/lib/python3.10/site-packages/numpy/distutils/core.py", line 24, in <module>
from numpy.distutils.command import config, config_compiler, \
File "/home/drjslab/.local/lib/python3.10/site-packages/numpy/distutils/command/config.py", line 19, in <module>
from numpy.distutils.mingw32ccompiler import generate_manifest
File "/home/drjslab/.local/lib/python3.10/site-packages/numpy/distutils/mingw32ccompiler.py", line 28, in <module>
from distutils.msvccompiler import get_build_version as get_build_msvc_version
ModuleNotFoundError: No module named 'distutils.msvccompiler'
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for scikit-learn
Running setup.py clean for scikit-learn
Failed to build scikit-learn
Installing collected packages: requests, pyaml, packaging, scikit-learn, deprecation
Attempting uninstall: scikit-learn
Found existing installation: scikit-learn 1.1.2
Uninstalling scikit-learn-1.1.2:
Successfully uninstalled scikit-learn-1.1.2
Running setup.py install for scikit-learn ... error
error: subprocess-exited-with-error
× Running setup.py install for scikit-learn did not run successfully.
│ exit code: 1
╰─> [26 lines of output]
Partial import of sklearn during the build process.
/tmp/pip-install-h9opcxf9/scikit-learn_fc42ebd0e5804549ad6f611dced79620/setup.py:123: DeprecationWarning:
`numpy.distutils` is deprecated since NumPy 1.23.0, as a result
of the deprecation of `distutils` itself. It will be removed for
Python >= 3.12. For older Python versions it will remain present.
It is recommended to use `setuptools < 60.0` for those Python versions.
For more details, see:
https://numpy.org/devdocs/reference/distutils_status_migration.html
from numpy.distutils.command.build_ext import build_ext # noqa
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-h9opcxf9/scikit-learn_fc42ebd0e5804549ad6f611dced79620/setup.py", line 303, in <module>
setup_package()
File "/tmp/pip-install-h9opcxf9/scikit-learn_fc42ebd0e5804549ad6f611dced79620/setup.py", line 295, in setup_package
from numpy.distutils.core import setup
File "/home/drjslab/.local/lib/python3.10/site-packages/numpy/distutils/core.py", line 24, in <module>
from numpy.distutils.command import config, config_compiler, \
File "/home/drjslab/.local/lib/python3.10/site-packages/numpy/distutils/command/config.py", line 19, in <module>
from numpy.distutils.mingw32ccompiler import generate_manifest
File "/home/drjslab/.local/lib/python3.10/site-packages/numpy/distutils/mingw32ccompiler.py", line 28, in <module>
from distutils.msvccompiler import get_build_version as get_build_msvc_version
ModuleNotFoundError: No module named 'distutils.msvccompiler'
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
Rolling back uninstall of scikit-learn
Moving to /home/drjslab/.local/lib/python3.10/site-packages/scikit_learn-1.1.2.dist-info/
from /home/drjslab/.local/lib/python3.10/site-packages/~cikit_learn-1.1.2.dist-info
Moving to /home/drjslab/.local/lib/python3.10/site-packages/scikit_learn.libs/
from /home/drjslab/.local/lib/python3.10/site-packages/~cikit_learn.libs
Moving to /home/drjslab/.local/lib/python3.10/site-packages/sklearn/
from /home/drjslab/.local/lib/python3.10/site-packages/~klearn
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> scikit-learn
note: This is an issue with the package mentioned above, not pip.
Environment:
Base OS: Ubuntu 20.04
Base Python version: 3.8
snips-nlu version:Latest
Docker OS: Ubuntu 20.04
Docker Python: 3.10.4
It seems a recent update of setuptools broke numpy.distutils which is a dependency of scikit-learn.
https://github.com/pypa/setuptools/pull/3505
A reported possible solution is to install setuptools<65 with pip install --no-use-pep517

Installing python module in Robomaker ROS workspace with colcon

I'm working on a cloud-based robotic application with AWS RoboMaker. I'm using ROS Kinetic, with the build tool colcon.
My robot application depends on a custom python module, which has to be in my workspace. This python module is built by colcon as a python package, not a ROS package. This page explains how to do that with catkin, but this example shows how to adapt it to colcon. So finally my workspace looks like that :
my_workspace/
|--src/
|--my_module/
| |--setup.py
| |--package.xml
| |--subfolders and python scripts...
|--some_ros_pkg1/
|--some_ros_pkg2/
|...
However the command : colcon build <my_workspace> builds all ROS packages but fails to build my python module as a package.
Here's the error I get :
Starting >>> my-module
[54.297s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'my-module' doesn't explicitly install a marker in the package index (colcon-ros currently does it implicitly but that fallback will be removed in the future)
[54.298s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'my-module' doesn't explicitly install the 'package.xml' file (colcon-ros currently does it implicitly but that fallback will be removed in the future)
--- stderr: my-module
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help
error: invalid command 'egg_info'
---
Failed <<< my-module [0.56s, exited with code 1]
I found this issue that seems correlated, and thus tried : pip install --upgrade setuptools
...Which fails with the error message :
Collecting setuptools
Using cached https://files.pythonhosted.org/packages/7c/1b/9b68465658cda69f33c31c4dbd511ac5648835680ea8de87ce05c81f95bf/setuptools-50.3.0.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "setuptools/__init__.py", line 16, in <module>
import setuptools.version
File "setuptools/version.py", line 1, in <module>
import pkg_resources
File "pkg_resources/__init__.py", line 1365
raise SyntaxError(e) from e
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-uwFamt/setuptools/
And with pip3 install --upgrade setuptools, I get :
Defaulting to user installation because normal site-packages is not writeable
Requirement already up-to-date: setuptools in /home/ubuntu/.local/lib/python3.5/site-packages (50.3.0)
I have both Python 3.5.2 an Python 2.7, but I don't know which one is used by colcon.
So I don't know what to try next, and what the real problem is. Any help welcome !
I managed to correctly install my package and its dependencies. I develop the method below, in case it may help someone someday !
I have been mainly inspired by this old DeepRacer repository.
The workspace tree in the question is wrong. It should look like this:
my_workspace/
|--src/
|--my_wrapper_package/
| |--setup.py
| |--my_package/
| |--__init__.py
| |--subfolders and python scripts...
|--some_ros_pkg1/
|--some_ros_pkg2/
my_wrapper_package may contain more than one python custom package.
A good setup.py example is this one.
You shouldn't put a package.xml next to setup.py : colcon will only look at the dependencies declared in package.xml, and won't collect pip packages.
It may help sometimes to delete the folders my_wrapper_package generated by colcon in install/ and build/. Doing so you force colcon to rebuild and bundle from scratch.

buildozer show me ModuleNotFoundError

I am trying to use chatterbot and kivy.
I tried to google search but without success.
I created this main.py file
from chatterbot import ChatBot
chatbot = ChatBot('Ron Obvious')
from kivy.app import App
from kivy.uix.button import Button
class TestApp(App):
def build(self):
resp = str(chatbot.get_response("ciao come stai?"))
return Button(text=resp)
TestApp().run()
and it works on my computer. I generate the apk for my android smartphone with:
buildozer android debug deploy run
As soon as I open it it closes. so using the command:
adb logcat | grep python
I found that:
05-19 18:12:18.526 17276 17309 I python : Traceback (most recent call last):
05-19 18:12:18.526 17276 17309 I python : File "/media/mezzo/4345727E5C539F3E/Dropbox/Home/Scrivania/app/.buildozer/android/app/main.py", line 1, in <module>
05-19 18:12:18.527 17276 17309 I python : ModuleNotFoundError: No module named 'chatterbot'
05-19 18:12:18.527 17276 17309 I python : Python for android ended.
how can i fix it? thanks.
Mention the requirement in buildozer.spec in home directory.
requirements = python3,chatterbot

How to fix numpy fail with missing libcblas.so.3 on alpine docker

I had installed numpy on alpine docker and everything looked good before running numpy:
Traceback (most recent call last):
File "/app/venv/lib/python3.7/site-packages/numpy/core/__init__.py", line 24, in <module>
from . import multiarray
File "/app/venv/lib/python3.7/site-packages/numpy/core/multiarray.py", line 14, in <module>
from . import overrides
File "/app/venv/lib/python3.7/site-packages/numpy/core/overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: Error loading shared library libcblas.so.3: No such file or directory (needed by /app/venv/lib/python3.7/site-packages/numpy/core/_multiarray_umath.cpython-37m-x86_64-linux-gnu.so)
I found that licblas.so might be in /usr/lib/ as mentioned here: alpine blas
but it wasn't there.
After installing lapack, the missing file libcblas.so.3 appeared in /usr/lib/:
apk add lapack
I had openblas-dev installed from before but that was not sufficient.

I properly installed PIL but still get the No Module Error

Grizz-MacBook-Pro:~ Grizz$ cd /usr/local/lib/python2.7/site-packages
Grizz-MacBook-Pro:site-packages Grizz$ ls
PIL pip-6.0.8-py2.7.egg
Pillow-2.7.0-py2.7.egg-info setuptools-12.0.5-py2.7.egg
PyQt4 setuptools.pth
easy-install.pth sip.so
hgext sipconfig.py
homebrew-pillow-nose.pth sipdistutils.py
mercurial sitecustomize.py
mercurial-3.3-py2.7.egg-info sitecustomize.pyc
It looks like PIL is installed in the correct PATH and when I go to use it in Sublime I get the:
'Traceback (most recent call last):
File "/Users/Grizz/Documents/Python Files/Weather APP/WeatherApp.py", line 4, in <module>
from PIL import Image
ImportError: No module named PIL
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "/Users/Grizz/Documents/Python Files/Weather APP/WeatherApp.py"]
[dir: /Users/Grizz/Documents/Python Files/Weather APP]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
I'm hoping to figure out either how to change the PIL path to ammend it to my system python path so I can run it in my interpreter or to uninstal and redownload PIL the correct way.
I'm new to Mac OS and have been able to troubleshoot most everything until now. I'm guessing it's because I'm running off my sys Python 2.7 and not a brew installeld 2.7... can someone walk me through this?

Resources