2

I am currently writing a PR for statsmodels the branch and the full code are available here (https://github.com/statsmodels/statsmodels/pull/2435)

This is the structure of my folder.

donbeo@donbeo-HP-EliteBook-Folio-9470m:~/Documents/statsmodels/statsmodels/sandbox$ tree gam_gsoc2015/
gam_gsoc2015/
├── draft.py
├── draft.py~
├── gam_example.py
├── gam_example.py~
├── gam_example.R
├── gam.py
├── gam.py~
├── __init__.py
├── __pycache__
│   ├── gam.cpython-34.pyc
│   ├── __init__.cpython-34.pyc
│   └── smooth_basis.cpython-34.pyc
├── smooth_basis.py
└── tests
    ├── __init__.py
    ├── __pycache__
    │   ├── __init__.cpython-34.pyc
    │   ├── test_gam.cpython-34.pyc
    │   └── test_smooth_basis.cpython-34.pyc
    ├── results
    │   └── prediction_from_mgcv.csv
    ├── test_gam.py
    ├── test_gam.py~
    ├── test_smooth_basis.py
    └── test_smooth_basis.py~

4 directories, 21 files
donbeo@do

both gam_example.py and test_gam.py import functions from gam.py

I am using pycharm community

I have marked the gam_gsoc2015 as sources root and I am able to run the gam_example or test_gam file from pycharm but I encounter a series of problems:

1) The gam_gsoc2015 folder is the only one in all the project marked in blue. (i.e. the only one marked as sources root)

2) I am not able to run tests with nosetest

donbeo@donbeo-HP-EliteBook-Folio-9470m:~/Documents/statsmodels/statsmodels/sandbox$ nosetests
................EE......................................................S...................
======================================================================
ERROR: Failure: ImportError (No module named 'smooth_basis')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/usr/local/lib/python3.4/dist-packages/nose/loader.py", line 414, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/local/lib/python3.4/dist-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/local/lib/python3.4/dist-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/python3.4/imp.py", line 235, in load_module
    return load_source(name, filename, file)
  File "/usr/lib/python3.4/imp.py", line 171, in load_source
    module = methods.load()
  File "<frozen importlib._bootstrap>", line 1220, in load
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1448, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/donbeo/Documents/statsmodels/statsmodels/sandbox/gam_gsoc2015/tests/test_gam.py", line 1, in <module>
    from smooth_basis import make_poly_basis, make_bsplines_basis
ImportError: No module named 'smooth_basis'

======================================================================
ERROR: Failure: ImportError (No module named 'smooth_basis')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/usr/local/lib/python3.4/dist-packages/nose/loader.py", line 414, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/local/lib/python3.4/dist-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/local/lib/python3.4/dist-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/python3.4/imp.py", line 235, in load_module
    return load_source(name, filename, file)
  File "/usr/lib/python3.4/imp.py", line 171, in load_source
    module = methods.load()
  File "<frozen importlib._bootstrap>", line 1220, in load
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1448, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/donbeo/Documents/statsmodels/statsmodels/sandbox/gam_gsoc2015/tests/test_smooth_basis.py", line 3, in <module>
    from smooth_basis import make_poly_basis, make_bsplines_basis
ImportError: No module named 'smooth_basis'

----------------------------------------------------------------------
Ran 91 tests in 21.727s

FAILED (SKIP=1, errors=2)
donbeo@donbeo-HP-EliteBook-Folio-9470m:~/Documents/statsmodels/statsmodels/sandbox$ 

3) If I try to run a file as for example gam_example in python console from pycharm I receive the following error

Backend TkAgg is interactive backend. Turning interactive mode on.
Traceback (most recent call last):
  File "<input>", line 3, in <module>
  File "/home/donbeo/Applications/pycharm-community-4.5.1/helpers/pydev/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ImportError: No module named 'smooth_basis'

I think that there is something wrong in the folder structure or I am doing something wrong.

What is the right way to solve?

I know some posts suggest to do a relative import path or add the folder to python path. But in this way the project would not be portable to other system and there is nothing like that for the other folders in the project.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.