I'm using anaconda to manage a virtual environment. I'm developing some Jupyter Notebooks and I'm using some functions in multiple Notebooks. So I want to extract these functions in a package, lets call it mytools
and import mytools
in my Notebooks. I installed the tools package from the parent dir with:
source activate myenv
pip install -e ./mytools/
And run the jupyter notebook server
source activate myenv
jupyter notebook
When I execute import mytools
I get the error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-cbc927808b4d> in <module>()
----> 1 import mytools
ImportError: No module named 'mytools'
Why can't I import it in the juypter notebook?
When I run pip list
in the conda environment I can see the installed package.
When I run:
import sys
sys.executable
it points to the myenv environment /Users/me/anaconda/envs/myenv/bin/python
My Folder structure:
├── Notebook Project1
│ └── Notebook1.ipynb
├── Notebook Project2
│ └── Notebook2.ipynb
└── mytools
├── __init__.py
├── module1
│ ├── modulecode.py
│ └── __init__.py
├── module2
│ ├── modulecode.py
│ └── __init__.py
└── setup.py
The problem was an error in the setup.py file.
This helped me to solve the errors: https://docs.python.org/3/distutils/setupscript.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.