sffjunkie / astral

Python calculations for the position of the sun and moon.
Apache License 2.0
237 stars 47 forks source link

Cannot import name 'LocationInfo' from 'astral' #58

Open matejmeglic opened 4 years ago

matejmeglic commented 4 years ago

Hello.

After installing astral with pip3 command (pip3 list returns --> astral 2.2 ), I cannot move forward from the code:

`#!/usr/bin/env python3

from astral import LocationInfo `

as I receive error: Traceback (most recent call last): File "astral.py", line 3, in <module> import astral File "/home/pi/python-scripts/astral.py", line 4, in <module> from astral import LocationInfo ImportError: cannot import name 'LocationInfo' from 'astral' (/home/pi/python-scripts/astral.py)

This is a noob question, but I don't have a solution? Thank you.

hudcap commented 4 years ago
Traceback (most recent call last): File "astral.py"

astral 2.2 does not have a file named astral.py, but the older versions did, so I'm going to assume that python is attempting the import from the old version.

notuntoward commented 4 years ago

I have the same problem, and I just installed astral today. The command I used was

pip install astral

which is the command I got from the astral v2.2 documentation.

Since I also see that astral.py was installed on my machine, there must be something wrong, either with the documentation or with pip.

Do you have any advice?

hudcap commented 4 years ago

What version do you see if you run pip show astral?

notuntoward commented 4 years ago

Here's the output of pip show astral:

Name: astral Version: 1.9.2 Summary: Calculations for the position of the sun and moon. Home-page: https://github.com/sffjunkie/astral Author: Simon Kennedy Author-email: sffjunkie+code@gmail.com License: Apache-2.0 Location: c:\users\scott\anaconda3\envs\keras\lib\site-packages Requires: pytz

Looks like whatever pip looks at is out of date? If it is, how do I get V2.2?

Thanks.

hudcap commented 4 years ago

Yup, that's why. Try pip install astral --upgrade

hudcap commented 4 years ago

It just occurred to me that if you installed it today and got the older version, you might be running an older version of python that is incompatible with the newer version of astral. Which python version are you running?

notuntoward commented 4 years ago

That fixed it. Thanks. Looks like it's the conda pvlib respository that's out of date (this is recommended by the pvlib docs, though).

Otherwise...

(keras) C:\Users\Scott\OneDrive - Clean Power Research\Research>conda install -c pvlib pvlib Collecting package metadata (current_repodata.json): done Solving environment: done

Package Plan

environment location: C:\Users\Scott\Anaconda3\envs\keras

added / updated specs:

  • pvlib

The following packages will be downloaded:

package                    |            build
---------------------------|-----------------
blosc-1.20.0               |       h7bd577a_0         142 KB
cftime-1.2.1               |   py37h2a96729_0         207 KB
curl-7.71.1                |       h2a8f88b_1         129 KB
ephem-3.7.7.0              |   py37he774522_0         710 KB
hdf4-4.2.13                |       h712560f_2         1.3 MB
krb5-1.18.2                |       hc04afaa_0         702 KB
libcurl-7.71.1             |       h2a8f88b_1         275 KB
libllvm9-9.0.1             |       h21ff451_0          61 KB
libnetcdf-4.7.3            |       h1302dcc_0         516 KB
libssh2-1.9.0              |       h7a1dbc1_1         215 KB
llvmlite-0.33.0            |   py37ha925a31_0        11.7 MB
lzo-2.10                   |       he774522_2         142 KB
mock-4.0.2                 |             py_0          32 KB
netcdf4-1.5.3              |   py37h012c1a0_0         353 KB
numba-0.50.1               |   py37h47e9c7a_0         3.0 MB
openssl-1.1.1g             |       he774522_1         4.8 MB
pvlib-0.8.0                |             py_0        20.0 MB  pvlib
snappy-1.1.8               |       h33f27b4_0          80 KB
tbb-2020.2                 |       h74a9793_0         165 KB
------------------------------------------------------------
                                       Total:        44.5 MB

The following NEW packages will be INSTALLED:

blosc pkgs/main/win-64::blosc-1.20.0-h7bd577a_0 bzip2 pkgs/main/win-64::bzip2-1.0.8-he774522_0 cftime pkgs/main/win-64::cftime-1.2.1-py37h2a96729_0 curl pkgs/main/win-64::curl-7.71.1-h2a8f88b_1 ephem pkgs/main/win-64::ephem-3.7.7.0-py37he774522_0 hdf4 pkgs/main/win-64::hdf4-4.2.13-h712560f_2 krb5 pkgs/main/win-64::krb5-1.18.2-hc04afaa_0 libcurl pkgs/main/win-64::libcurl-7.71.1-h2a8f88b_1 libllvm9 pkgs/main/win-64::libllvm9-9.0.1-h21ff451_0 libnetcdf pkgs/main/win-64::libnetcdf-4.7.3-h1302dcc_0 libssh2 pkgs/main/win-64::libssh2-1.9.0-h7a1dbc1_1 llvmlite pkgs/main/win-64::llvmlite-0.33.0-py37ha925a31_0 lzo pkgs/main/win-64::lzo-2.10-he774522_2 mock pkgs/main/noarch::mock-4.0.2-py_0 netcdf4 pkgs/main/win-64::netcdf4-1.5.3-py37h012c1a0_0 numba pkgs/main/win-64::numba-0.50.1-py37h47e9c7a_0 numexpr pkgs/main/win-64::numexpr-2.7.1-py37h25d0782_0 pvlib pvlib/noarch::pvlib-0.8.0-py_0 pytables pkgs/main/win-64::pytables-3.6.1-py37h1da0976_0 snappy pkgs/main/win-64::snappy-1.1.8-h33f27b4_0 tbb pkgs/main/win-64::tbb-2020.2-h74a9793_0

The following packages will be UPDATED:

ca-certificates conda-forge::ca-certificates-2020.6.2~ --> pkgs/main::ca-certificates-2020.7.22-0

The following packages will be SUPERSEDED by a higher-priority channel:

certifi conda-forge::certifi-2020.6.20-py37hc~ --> pkgs/main::certifi-2020.6.20-py37_0 openssl conda-forge --> pkgs/main

Proceed ([y]/n)? y

Downloading and Extracting Packages libllvm9-9.0.1 | 61 KB | ############################################################################ | 100% libcurl-7.71.1 | 275 KB | ############################################################################ | 100% ephem-3.7.7.0 | 710 KB | ############################################################################ | 100% pvlib-0.8.0 | 20.0 MB | ############################################################################ | 100% libnetcdf-4.7.3 | 516 KB | ############################################################################ | 100% tbb-2020.2 | 165 KB | ############################################################################ | 100% mock-4.0.2 | 32 KB | ############################################################################ | 100% llvmlite-0.33.0 | 11.7 MB | ############################################################################ | 100% cftime-1.2.1 | 207 KB | ############################################################################ | 100% hdf4-4.2.13 | 1.3 MB | ############################################################################ | 100% krb5-1.18.2 | 702 KB | ############################################################################ | 100% lzo-2.10 | 142 KB | ############################################################################ | 100% numba-0.50.1 | 3.0 MB | ############################################################################ | 100% libssh2-1.9.0 | 215 KB | ############################################################################ | 100% openssl-1.1.1g | 4.8 MB | ############################################################################ | 100% snappy-1.1.8 | 80 KB | ############################################################################ | 100% curl-7.71.1 | 129 KB | ############################################################################ | 100% netcdf4-1.5.3 | 353 KB | ############################################################################ | 100% blosc-1.20.0 | 142 KB | ############################################################################ | 100% Preparing transaction: done Verifying transaction: done Executing transaction: done

(keras) C:\Users\Scott\OneDrive - Clean Power Research\Research> pip show astral Name: astral Version: 1.9.2 Summary: Calculations for the position of the sun and moon. Home-page: https://github.com/sffjunkie/astral Author: Simon Kennedy Author-email: sffjunkie+code@gmail.com License: Apache-2.0 Location: c:\users\scott\anaconda3\envs\keras\lib\site-packages Requires: pytz Required-by:

(keras) C:\Users\Scott\OneDrive - Clean Power Research\Research>pip install astral --upgrade Collecting astral Downloading astral-2.2-py2.py3-none-any.whl (30 kB) Requirement already satisfied, skipping upgrade: pytz in c:\users\scott\anaconda3\envs\keras\lib\site-packages (from astral) (2020.1) Installing collected packages: astral Attempting uninstall: astral Found existing installation: astral 1.9.2 Uninstalling astral-1.9.2: Successfully uninstalled astral-1.9.2 Successfully installed astral-2.2

(keras) C:\Users\Scott\OneDrive - Clean Power Research\Research> pip show astral Name: astral Version: 2.2 Summary: Calculations for the position of the sun and moon. Home-page: https://github.com/sffjunkie/astral Author: Simon Kennedy Author-email: sffjunkie+code@gmail.com License: Apache-2.0 Location: c:\users\scott\anaconda3\envs\keras\lib\site-packages Requires: pytz

lmcook88 commented 3 years ago

Hello, I am having the same issue.

ImportError: cannot import name 'LocationInfo' from 'astral' (/Users/cooklaur/python/ve1/lib/python3.9/site-packages/astral.py)

I tried using the older version 1.10.1 and updating gw2pvo-docker as recommended on this thread: [https://github.com/markruys/gw2pvo/issues/37]. Neither fixed the isse.

I also updated astral to the latest version, recommded here, but this did not work.

This command, however, does work: from astral import Astral

I am using a virtual environment with python3.9. I am not using conda.

Any suggestions? Thank you.

lmcook88 commented 3 years ago

Ok, so I am not sure why, but uninstalling astral and then reinstalling the latest version again seemed to fix the issue. from astral import Astral no longer works, which I guess is an update for the newest version.