Very recently I've been getting ImportErrors when running a Python script. The script (graph.py) lives within a Flask app that I have Dockerized.
When I was running python webtools/tools/graph.py (full file dir below) I would get this error:
AttributeError: module 'numpy' has no attribute 'random'
at the line where I import pandas (import pandas as pd).
When I run Python interactively, I can run import pandas just fine -- as well as import numpy -- EXCEPT after I cd into webtools/tools. When I'm in that directory and run Python interactively, I get an error with import pandas and import numpy:
ImportError: Unable to import required dependencies:
numpy: cannot import name randbits
and
ImportError: cannot import name randbits
I currently have following package versions installed:
numpy==1.23.2
pandas==1.4.3
conda version : 4.12.0
conda-build version : 3.21.8
python version : 3.9.12.final.0
I don't understand why this package error occurs depending on what my current directory is. I'm also wondering if the fact that I installed the packages via pip while running in Anaconda has something to do with it.
Recap:
- No issue importing numpyfrom other working directories
- No issues building Docker image and running container
.
├── Dockerfile
├── Makefile
├── README.md
├── __pycache__
├── atlantis.yaml
├── dist
│   └── ...
├── webtools
│   ├── __init__.py
│   ├── __pycache__
│   ├── lib
│   ├── static
│   ├── templates
│   ├── tools  ### Doesn't work when I've cd into here
│   │   ├── __pycache__
│   │   ├── apollo-272319-1425111bd2ab.json
│   │   ├── graph.py
│   │   ├── map_params.yml
│   │   └── secrets.py
│   └── views.py
├── webtools.egg-info
├── requirements.txt
├── setup.py
├── terraform
└── tests
 
    