# Python import error in Docker compoment

**URL:** <https://forums.docker.com/t/python-import-error-in-docker-compoment/147698>\
**Category:** General\
**Tags:** docker, python\
**Created:** [April 15, 2025, 8:07am UTC](https://forums.docker.com/t/python-import-error-in-docker-compoment/147698 "2025-04-15T08:07:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstcood](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/cstcood/32/55032_2.png) [@cstcood](https://forums.docker.com/u/cstcood)\
**Post date:** [April 15, 2025, 8:07am UTC](https://forums.docker.com/t/python-import-error-in-docker-compoment/147698/1 "2025-04-15T08:07:34Z")

</div>

I try to package my code in image using code below:

```auto
FROM torch_gpu:v1
WORKDIR /app
COPY ./code/* ./
CMD ["python","main.py"]

```

when I try to run it with `docker run `. It goes wrong with

```auto
  File "/app/main.py", line 30, in load_AU_model
    from OpenGraphAU.conf import get_config, set_env, set_outdir, set_logger
ModuleNotFoundError: No module named 'OpenGraphAU'

```

The file dir tree is

```auto
/app
---/OpenGraphAU
   ----conf.py
---main.py

```

I don’t kown where is wrong and how to fix it?

but when I try run it with `docker run --mount type=bind,source=./code,target=/app`, it work well.

I have added code to changed envirment var and it work well

```python
os.chdir("/app")
curPath = os.path.abspath(os.path.dirname( __file__ ))
rootPath = os.path.split(curPath)[0]
sys.path.insert(0, os.path.split(rootPath)[0])
sys.path.remove("/") 
print(sys.path)

```

and ouput

```auto
['/app', '/opt/conda/lib/python311.zip', '/opt/conda/lib/python3.11', '/opt/conda/lib/python3.11/lib-dynload', '/opt/conda/lib/python3.11/site-packages', '/opt/conda/lib/python3.11/site-packages/setuptools/_vendor', '/tmp/tmpz4y0cvod']

```

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [April 16, 2025, 9:44pm UTC](https://forums.docker.com/t/python-import-error-in-docker-compoment/147698/2 "2025-04-16T21:44:02Z")

</div>

> [@cstcood](#):
>
> The file dir tree is

Where did you run the command to test it (in the container or on the host) and what command you ran? If mounting works but copying files into the image doesn’t, you either copy the wrong files or to the wrong folder in the image, or when you run the container you override the original code and eventually it will not be found in the container even if it was in the image..

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/docker/original/3X/d/4/d4fbccd46c81bfcffe9822e20e17736d946fa821.png) [@system](https://forums.docker.com/u/system)\
**Post date:** [May 16, 2025, 9:44pm UTC](https://forums.docker.com/t/python-import-error-in-docker-compoment/147698/3 "2025-05-16T21:44:30Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
