Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python 'import' package works in shell but not in Jupyter Notebook; issues with setup.py #143

Closed
robertdefilippi opened this issue Sep 21, 2018 · 3 comments

Comments

@robertdefilippi
Copy link

I'm trying to import a custom package(s) into my Jupyter Notebook, but I'm having issues using the setup_tools provided by cookiecutter. The package(s) work when I open my termina and run the python3 shell, however I get a 'no module error' when importing the package into my notebook.

I've set up a virtual environment with python3 -m venv and installed the setup.py with pip3 install --editable .

This is my project structure, which is exactly what is provided in cookiecutter

./-- notebook -- my_notebook.ipynb
  └── src -- funct -- func.py
  └── setup.py

I also know I've correctly installed the package:

$ pip3 list
Package    Version Location
---------- ------- -------------------------------------------------------
pip        18.0
setuptools 39.0.1
src        0.1.0   /Users/me/project

In my terminal:

$ python3
>>> import src
>>> from src.funct import func
>>> func.foo()
'Foo'

However, when I run import src in my notebook, I get:

import src
ImportError: No module named src

This is my setup.py

setup(
    name='src',
    packages=find_packages(),
    version='0.1.0',
    description='Example',
    author='me',
    license='MIT',
)

If the package can be imported correctly into my python shell, why can't it be imported into my notebook? Is this a permissions issue, and if so how can I check that?

Here is the SOURCES.txt generated from the setup.py

README.md
src/__init__.py
src.egg-info/PKG-INFO
src.egg-info/SOURCES.txt
src.egg-info/dependency_links.txt
src.egg-info/top_level.txt
src/funct/__init__.py
src/funct/func.py

So now I'm more confused on why it won't import.

Any help would be appreciated.

@pjbull
Copy link
Member

pjbull commented Sep 21, 2018

I would guess that when you run jupyter it is not part of your environment where the package is installed.

If you run which python3 you should see the environment name in the path to the python3 executable. If you run which jupyter I suspect you will not see your environment name in the path.

To fix this, within the environment run pip install jupyter. Then if you use the jupyter within the environment, it should work. (Check by running which jupyter again).

@robertdefilippi
Copy link
Author

robertdefilippi commented Sep 21, 2018

# without the virtual env
$ which python3
/usr/local/bin/python3

# with the virtual env
$ which python3
/Users/foo/cookiecutter/bin/python3
$ which python
/usr/bin/python
$ which jupyter
/usr/local/bin/jupyter

I'll try pip install jupyter within the virtual environment, and get back to you.

@pjbull
Copy link
Member

pjbull commented Sep 23, 2018

Closing, since this isn't a package issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants