Plasmapy: ModuleNotFoundError: No module named 'plasmapy.classes' on plasmapy import

Created on 26 Sep 2017  Β·  15Comments  Β·  Source: PlasmaPy/PlasmaPy

On importing freshly installed plasmapy into a new environment:

(plasmapy) [~]$ python
Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 13:51:32) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import plasmapy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dominik/.anaconda3/envs/plasmapy/lib/python3.6/site-packages/plasmapy/__init__.py", line 8, in <module>
    from .classes import Plasma
ModuleNotFoundError: No module named 'plasmapy.classes'

The goal of this one is being able to import plasmapy. At all.

The issue likely lies in plasmapy/__init__.py.

To quote @cadair 's words of encouragement on this bugfixing journey, packaging is a special kind of hell.

Bug low

Most helpful comment

If you stated your python session in the root directory of this repo, you would be able to import plasmapy.classes since the root directory would be part of the PYTHONPATH.

If you installed plasmapy with pip install . or python setup.py install and moved to another directory, the original setup.py only installed plasmapy/_metadata.py and plasmapy/__init__.py, leaving out all the other modules.

All 15 comments

Did this get fixed? I tried to recreate the problem and everything seemed to work for me.

haggerty@Colbylpt:~/Programing/PlasmaPy:master> source activate plasmapy
(plasmapy)  haggerty@Colbylpt:~/Programing/PlasmaPy:master> pip install .
Processing /Users/haggerty/Programing/PlasmaPy
Collecting numpy (from plasmapy==0.1.dev1)
  Using cached numpy-1.13.1-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting scipy (from plasmapy==0.1.dev1)
  Using cached scipy-0.19.1-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting astropy (from plasmapy==0.1.dev1)
  Downloading astropy-2.0.2-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (7.6MB)
    100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 7.6MB 88kB/s
Collecting coveralls (from plasmapy==0.1.dev1)
  Using cached coveralls-1.2.0-py2.py3-none-any.whl
Collecting pytest>=2.8 (from astropy->plasmapy==0.1.dev1)
  Using cached pytest-3.2.2-py2.py3-none-any.whl
Collecting docopt>=0.6.1 (from coveralls->plasmapy==0.1.dev1)
Collecting requests>=1.0.0 (from coveralls->plasmapy==0.1.dev1)
  Using cached requests-2.18.4-py2.py3-none-any.whl
Collecting coverage>=3.6 (from coveralls->plasmapy==0.1.dev1)
  Using cached coverage-4.4.1-cp36-cp36m-macosx_10_10_x86_64.whl
Requirement already satisfied: setuptools in /Users/haggerty/anaconda/envs/plasmapy/lib/python3.6/site-packages (from pytest>=2.8->astropy->plasmapy==0.1.dev1)
Collecting py>=1.4.33 (from pytest>=2.8->astropy->plasmapy==0.1.dev1)
  Using cached py-1.4.34-py2.py3-none-any.whl
Collecting idna<2.7,>=2.5 (from requests>=1.0.0->coveralls->plasmapy==0.1.dev1)
  Using cached idna-2.6-py2.py3-none-any.whl
Collecting urllib3<1.23,>=1.21.1 (from requests>=1.0.0->coveralls->plasmapy==0.1.dev1)
  Using cached urllib3-1.22-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests>=1.0.0->coveralls->plasmapy==0.1.dev1)
  Using cached chardet-3.0.4-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests>=1.0.0->coveralls->plasmapy==0.1.dev1)
  Using cached certifi-2017.7.27.1-py2.py3-none-any.whl
Installing collected packages: numpy, scipy, py, pytest, astropy, docopt, idna, urllib3, chardet, certifi, requests, coverage, coveralls, plasmapy
  Found existing installation: certifi 2016.2.28
    Uninstalling certifi-2016.2.28:
      Successfully uninstalled certifi-2016.2.28
  Running setup.py install for plasmapy ... done
Successfully installed astropy-2.0.2 certifi-2017.7.27.1 chardet-3.0.4 coverage-4.4.1 coveralls-1.2.0 docopt-0.6.2 idna-2.6 numpy-1.13.1 plasmapy-0.1.dev1 py-1.4.34 pytest-3.2.2 requests-2.18.4 scipy-0.19.1 urllib3-1.22

The install looks good to me.

(plasmapy)  haggerty@Colbylpt:~/Programing/PlasmaPy:master> python
Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 13:14:59)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import plasmapy
>>>

And no errors on the import.

Are you still getting this @StanczakDominik ?

Yeah, just confirmed as still happening on two separate machines. Weird... :confused:

Is your branch up to date? I started working on this issue because I had this exact same problem a few weeks back, so I figured I would try to fix it, but now I am not getting it any more.

What do you mean by branch here? I'm running this in a completely clean conda env on a laptop that hasn't had anything to do with PlasmaPy, so nothing I did on any of my git branches should be of any importance, right?

Sorry I meant, is whatever current branch on your local repository up-to-date with the plasmapy master branch on github?

Where did you grab plasmapy from? plasmapy/plasmapy/master or something like StanczakDominik/PlasmaPy/particle_step ?

It is, but that's irrelevant to the laptop. @SolarDrew says on Matrix he's got the same issue going on, so maybe something's weird with your config? You're outnumbered 2:1 right now :D

I can also confirm this bug.
screenshot

If you stated your python session in the root directory of this repo, you would be able to import plasmapy.classes since the root directory would be part of the PYTHONPATH.

If you installed plasmapy with pip install . or python setup.py install and moved to another directory, the original setup.py only installed plasmapy/_metadata.py and plasmapy/__init__.py, leaving out all the other modules.

It looks like our init might be wrong. So if you checkout the file it is yelling about it is just plasmapy's __init__.py file moved to /Users/colbych/anaconda/envs/plasmapy/lib/python3.6/site-packages/plasmapy/__init__.py and then that is trying to load files from ..

I started looking at how astropy does it and it seems pretty different. I am going to keep looking into this unless other people have it figured out already.

Complex projects will do a bunch of cool weird stuff in their init files. Might be a massive ordeal to figure something out from that.

Wouldn't switching lines 8-9 here solve the problem?

It doesn't look like you can just switch the lines. This is what I get when I tried:

Traceback (most recent call last):
  File "test_import.py", line 1, in <module>
    import plasmapy
  File "/Users/colbych/anaconda/envs/plasmapy/lib/python3.6/site-packages/plasmapy/__init__.py", line 8, in <module>
    from . import classes
ImportError: cannot import name 'classes'

Well, it was worth a try.

On Sep 27, 2017 9:28 PM, "Colby Haggerty" notifications@github.com wrote:

It doesn't look like you can just switch the lines. This is what I get
when I tried:

Traceback (most recent call last):
File "test_import.py", line 1, in
import plasmapy
File "/Users/colbych/anaconda/envs/plasmapy/lib/python3.6/site-packages/plasmapy/__init__.py", line 8, in
from . import classes
ImportError: cannot import name 'classes'

β€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/PlasmaPy/PlasmaPy/issues/121#issuecomment-332629977,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AKxDLyIQxape1IwB0Q-M9_rc-NqPCugWks5smqHdgaJpZM4PkfN0
.

I don’t think there are any issues with the plasmapy/__init__.py. You can test out the fix in my pull request by starting a clean environment and running:

$ pip install git+https://github.com/thomasjpfan/PlasmaPy@setup_fix

Yup I just tried it and your branch fixes it.

Wow, yeah, it does work! @thomasjpfan, thank you for the fix and for your patience with us while we figure out how packaging works and how to actually test this! :smiley:

Was this page helpful?
0 / 5 - 0 ratings