Reputation: 17617
I am trying to create a python package but I am having issues with imports. This is the current situation:
[lpuggini@machinelearn-1 src]$ source ~/VirtualEnvs/time_series_algorithms_venv/bin/activate
(time_series_algorithms_venv) [lpuggini@machinelearn-1 src]$ tree
.
|-- TimeSeriesAlgorithms.egg-info
| |-- PKG-INFO
| |-- SOURCES.txt
| |-- dependency_links.txt
| `-- top_level.txt
|-- requirements.txt
|-- setup.py
`-- time_series_algorithms
|-- __init__.py
|-- __init__.pyc
|-- examples
| |-- example_percentage_variation.py
| `-- example_percentage_variation.py~
|-- percentage_varation.py
`-- percentage_varation.pyc
3 directories, 12 files
(time_series_algorithms_venv) [lpuggini@machinelearn-1 src]$ python setup.py develop
/home/lpuggini/VirtualEnvs/time_series_algorithms_venv/lib/python2.7/site-packages/setuptools/dist.py:475: UserWarning: Normalizing '0.1dev' to '0.1.dev0'
normalized_version,
running develop
running egg_info
writing TimeSeriesAlgorithms.egg-info/PKG-INFO
writing top-level names to TimeSeriesAlgorithms.egg-info/top_level.txt
writing dependency_links to TimeSeriesAlgorithms.egg-info/dependency_links.txt
reading manifest file 'TimeSeriesAlgorithms.egg-info/SOURCES.txt'
writing manifest file 'TimeSeriesAlgorithms.egg-info/SOURCES.txt'
running build_ext
Creating /home/lpuggini/VirtualEnvs/time_series_algorithms_venv/lib/python2.7/site-packages/TimeSeriesAlgorithms.egg-link (link to .)
TimeSeriesAlgorithms 0.1.dev0 is already the active version in easy-install.pth
Installed /home/lpuggini/mlp/time_series_algorithms/trunk/src
Processing dependencies for TimeSeriesAlgorithms==0.1.dev0
Finished processing dependencies for TimeSeriesAlgorithms==0.1.dev0
and then when I try to run some code I get the following error:
(time_series_algorithms_venv) [lpuggini@machinelearn-1 src]$ python time_series_algorithms/examples/example_percentage_variation.py
Traceback (most recent call last):
File "time_series_algorithms/examples/example_percentage_variation.py", line 2, in <module>
from time_series_algorithms.percentage_variation import PercentageVariationAD, PercentageVariationADConfig
ImportError: No module named percentage_variation
(time_series_algorithms_venv) [lpuggini@machinelearn-1 src]$
This is my setup.py
file
(time_series_algorithms_venv) [lpuggini@machinelearn-1 src]$ cat setup.py
from setuptools import setup, find_packages
setup(
name='TimeSeriesAlgorithms',
version='0.1dev',
packages=find_packages(),
)
(time_series_algorithms_venv) [lpuggini@machinelearn-1 src]$
I do not know why this import is failing. I am using python 2.7
NOTE:
I am able to import the module but not the python file:
(time_series_algorithms_venv) [lpuggini@machinelearn-1 ~]$ python
Python 2.7.5 (default, Oct 30 2018, 23:45:53)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time_series_algorithms
>>> from time_series_algorithms import percentage_variation
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name percentage_variation
>>>
[
ANSWER TO THE COMMENTS 1: Also the option suggested in the comments fails
(time_series_algorithms_venv) [lpuggini@machinelearn-1 src]$ python time_series_algorithms/examples/example_percentage_variation.py
Traceback (most recent call last):
File "time_series_algorithms/examples/example_percentage_variation.py", line 2, in <module>
from TimeSeriesAlgorithms.time_series_algorithms.percentage_variation import PercentageVariationAD, PercentageVariationADConfig
ImportError: No module named TimeSeriesAlgorithms.time_series_algorithms.percentage_variation
(time_series_algorithms_venv) [lpuggini@machinelearn-1 src]$
Upvotes: 0
Views: 274
Reputation: 94654
This is a simple typo in the name of the file that the OP has:
The file is called:
time_series_algorithms/percentage_varation.py
and the import statement is:
from time_series_algorithms.percentage_variation import PercentageVariationAD, PercentageVariationADConfig
so the file is varation
and the import is variation
.
This would have probably been observable in an IDE, or an strace of the python script itself would have revealed it being unable to open the percentage_variation.py
file even though it looks to be there.
Upvotes: 2