![]() ![]() In addition, your current directory (which you can set in your Dockerfile using WORKDIR), must be the same directory where your code sits. If you’re using python -m yourpackage or python -m yourmodule, and you haven’t just pip installed everything, then you need to follow the same requirements as step 3: the imported code needs to be in the same directory as the main script. python -m requires the code to be in the current working directory whether or not you have multiple versions of Python installed. SolutionĮither install all your code with pip install, or make sure it’s all in the same directory. What matters is that the code you’re importing is in the same directory as the main script you’re running. Notice that your current working directory doesn’t matter. ModuleNotFoundError: No module named 'library'įile "./main.py", line 1, in import library ![]() You can seem them by looking at sys.path:įile "main.py", line 1, in import library To begin with, Python has a series of standard directories where it checks for imports. This is where you need to start understanding how Python decides where you can import code from. If it’s not pip installed, make sure the code location is correct Make sure you are correctly activating your virtualenv, or correctly activating your Conda environment. You want to make sure your code is installed and run from the same one. ![]() If you’re using an isolated environment like a virtualenv or Conda environment, you’re in a similar situation to the above: you have two different versions of Python, the system Python and the isolated environment. If relevant, are you successfully activating your virtualenv/conda env? Install Python libraries using pip, not apt-get.If you’re installing system packages, check if Python is one of the dependent system packages installed, and if so make sure you’re using the /usr/local/bin/ version.This mostly happens if you’re (mis)using the official python base image. Sometimes this happens less visibly, when you install a system package that depends on a python or python3 system package, or try to install a library by doing apt-get install python3-numpy. In /usr/bin/python3 is the Python interpreter installed via apt-get./usr/local/bin/python is the Python interpreter provided by the Docker image.Need to ship quickly, and don’t have time to figure out every detail on your own? Read the concise, action-oriented Python on Docker Production Handbook. Note: Outside any specific best practice being demonstrated, the Dockerfiles in this article are not examples of best practices, since the added complexity would obscure the main point of the article. FROM python:3.8-slim-buster RUN apt-get update & apt-get install -y python3 python3-pipĮNTRYPOINT ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |