open-meteo / python-requests

Open-Meteo Python Library using `requests`
MIT License
15 stars 4 forks source link

Importing openmeteo_requests takes 87 seconds #62

Closed carbon-starlight closed 5 months ago

carbon-starlight commented 5 months ago

Importing openmeteo_requests usually takes more than 30 seconds, sometimes up to 90. Debian 12, IA-32. Consistently in the same .venv

My -X importtime -c
(.venv) user@debian:~/Projects/WikiSchedule$ python3 -X importtime -c "import openmeteo_requests"
import time: self [us] | cumulative | imported package
import time:      1525 |       1525 |   _io
import time:       642 |        642 |   marshal
import time:      3721 |       3721 |   posix
import time:      3309 |       9195 | _frozen_importlib_external
import time:       841 |        841 |   time
import time:      1241 |       2081 | zipimport
import time:       367 |        367 |     _codecs
import time:      2191 |       2557 |   codecs
import time:      3286 |       3286 |   encodings.aliases
import time:      4431 |      10272 | encodings
import time:      2079 |       2079 | encodings.utf_8
import time:       755 |        755 | _signal
import time:       382 |        382 |     _abc
import time:      1265 |       1646 |   abc
import time:      1616 |       3262 | io
import time:       403 |        403 |       _stat
import time:       560 |        963 |     stat
import time:      5661 |       5661 |     _collections_abc
import time:       346 |        346 |       genericpath
import time:       755 |       1101 |     posixpath
import time:      2857 |      10580 |   os
import time:       647 |        647 |   _sitebuiltins
import time:      3676 |       3676 |   _distutils_hack
import time:       542 |        542 |     apport_python_hook
import time:      1040 |       1581 |   sitecustomize
import time:      6395 |      22878 | site
import time:      1574 |       1574 |   __future__
import time:       708 |        708 |         itertools
import time:      1394 |       1394 |         keyword
import time:       511 |        511 |           _operator
import time:      3213 |       3724 |         operator
import time:      1488 |       1488 |         reprlib
import time:       627 |        627 |         _collections
import time:      5951 |      13889 |       collections
import time:      1471 |       1471 |       collections.abc
import time:      1882 |       1882 |           types
import time:       730 |        730 |           _functools
import time:      4587 |       7198 |         functools
import time:      5082 |      12279 |       contextlib
import time:     12115 |      12115 |         enum
import time:       727 |        727 |           _sre
import time:      1899 |       1899 |             re._constants
import time:      3325 |       5224 |           re._parser
import time:      1366 |       1366 |           re._casefix
import time:      2962 |      10277 |         re._compiler
import time:      1515 |       1515 |         copyreg
import time:      4200 |      28106 |       re
import time:      3267 |       3267 |       warnings
import time:      1275 |       1275 |       _typing
import time:     17440 |      77724 |     typing
import time:      1378 |       1378 |                 token
import time:      6182 |       7559 |               tokenize
import time:      1224 |       8782 |             linecache
import time:      6832 |       6832 |             textwrap
import time:      4215 |      19828 |           traceback
import time:      1477 |       1477 |             _weakrefset
import time:      3215 |       4691 |           weakref
import time:       326 |        326 |             _string
import time:      4799 |       5125 |           string
import time:      5626 |       5626 |           threading
import time:       557 |        557 |           atexit
import time:     13637 |      49461 |         logging
import time:      1267 |       1267 |             _socket
import time:       393 |        393 |               math
import time:       588 |        588 |               select
import time:      4223 |       5203 |             selectors
import time:       589 |        589 |             errno
import time:       482 |        482 |             array
import time:     12099 |      19638 |           socket
import time:      1386 |       1386 |             email
import time:      3701 |       5087 |           email.errors
import time:      6520 |       6520 |             http
import time:       475 |        475 |                     binascii
import time:      2257 |       2257 |                     email.quoprimime
import time:       997 |        997 |                           _struct
import time:      1195 |       2191 |                         struct
import time:      2012 |       4203 |                       base64
import time:      1588 |       5790 |                     email.base64mime
import time:      1443 |       1443 |                         quopri
import time:      1172 |       2615 |                       email.encoders
import time:      2201 |       4816 |                     email.charset
import time:      5088 |      18425 |                   email.header
import time:       276 |        276 |                         _bisect
import time:      1551 |       1827 |                       bisect
import time:       438 |        438 |                       _random
import time:       475 |        475 |                       _sha512
import time:      3009 |       5748 |                     random
import time:      6257 |       6257 |                       _datetime
import time:      6641 |      12897 |                     datetime
import time:      1482 |       1482 |                       urllib
import time:      6111 |       7592 |                     urllib.parse
import time:       533 |        533 |                           _locale
import time:      5149 |       5681 |                         locale
import time:      4112 |       9792 |                       calendar
import time:      2221 |      12013 |                     email._parseaddr
import time:      4095 |      42343 |                   email.utils
import time:      2194 |      62961 |                 email._policybase
import time:      4168 |      67128 |               email.feedparser
import time:      1874 |      69002 |             email.parser
import time:      2207 |       2207 |               email._encoded_words
import time:      1224 |       1224 |               email.iterators
import time:      5289 |       8718 |             email.message
import time:     13741 |      13741 |               _ssl
import time:     20104 |      33845 |             ssl
import time:      7436 |     125518 |           http.client
import time:      6719 |     156960 |         urllib3.exceptions
import time:      2407 |       2407 |                 urllib3.util.timeout
import time:      2429 |       4835 |               urllib3.util.connection
import time:      1213 |       1213 |                 urllib3.util.util
import time:       852 |        852 |                 brotlicffi
import time:       837 |        837 |                 brotli
import time:       879 |        879 |                 zstandard
import time:     12162 |      15942 |               urllib3.util.request
import time:      1398 |       1398 |               urllib3.util.response
import time:      3567 |       3567 |               urllib3.util.retry
import time:      6735 |       6735 |                   _hashlib
import time:       529 |        529 |                     _blake2
import time:      2746 |       3275 |                   hashlib
import time:      2100 |      12109 |                 hmac
import time:     58722 |      58722 |                 urllib3.util.url
import time:      2028 |       2028 |                 urllib3.util.ssltransport
import time:      3467 |      76324 |               urllib3.util.ssl_
import time:      1268 |       1268 |               urllib3.util.wait
import time:      1821 |     105153 |             urllib3.util
import time:       257 |     105409 |           urllib3.util.connection
import time:      5629 |     111037 |         urllib3._base_connection
import time:      5086 |       5086 |         urllib3._collections
import time:      1244 |       1244 |         urllib3._version
import time:       316 |        316 |               _heapq
import time:      1604 |       1920 |             heapq
import time:      1515 |       1515 |             _queue
import time:      2091 |       5525 |           queue
import time:      1310 |       1310 |                   _json
import time:      2694 |       4003 |                 json.scanner
import time:      3224 |       7227 |               json.decoder
import time:      3235 |       3235 |               json.encoder
import time:      5409 |      15869 |             json
import time:       651 |        651 |                   _winapi
import time:       880 |        880 |                   winreg
import time:      2321 |       3852 |                 mimetypes
import time:      2443 |       6294 |               urllib3.fields
import time:      2560 |       8854 |             urllib3.filepost
import time:       602 |        602 |               zlib
import time:       813 |        813 |               brotlicffi
import time:       889 |        889 |               brotli
import time:       981 |        981 |               zstandard
import time:      8683 |       8683 |                   ipaddress
import time:      1526 |      10208 |                 urllib3.util.ssl_match_hostname
import time:      5525 |      15733 |               urllib3.connection
import time:      4705 |      23719 |             urllib3.response
import time:      2733 |      51174 |           urllib3._request_methods
import time:      1308 |       1308 |           urllib3.util.proxy
import time:      3729 |      61733 |         urllib3.connectionpool
import time:      7323 |       7323 |         urllib3.poolmanager
import time:      2994 |     395836 |       urllib3
import time:       643 |        643 |           chardet
import time:      1518 |       1518 |                 importlib
import time:      8495 |       8495 |                 charset_normalizer.constant
import time:      1810 |       1810 |                   charset_normalizer.md__mypyc
import time:       448 |        448 |                     unicodedata
import time:      2378 |       2378 |                     _multibytecodec
import time:      3596 |       6422 |                   charset_normalizer.utils
import time:      4081 |      12312 |                 charset_normalizer.md
import time:      5107 |       5107 |                 charset_normalizer.models
import time:      3640 |      31070 |               charset_normalizer.cd
import time:      3914 |      34984 |             charset_normalizer.api
import time:      3108 |       3108 |             charset_normalizer.legacy
import time:      1352 |       1352 |             charset_normalizer.version
import time:      2362 |      41805 |           charset_normalizer
import time:      1142 |       1142 |           simplejson
import time:      1068 |       1068 |                   org
import time:       265 |       1333 |                 org.python
import time:       225 |       1558 |               org.python.core
import time:      2098 |       3655 |             copy
import time:      1718 |       1718 |                   fnmatch
import time:      2282 |       2282 |                     _compression
import time:      2404 |       2404 |                     _bz2
import time:      2441 |       7126 |                   bz2
import time:      2960 |       2960 |                     _lzma
import time:      2705 |       5664 |                   lzma
import time:     13399 |      27906 |                 shutil
import time:     11838 |      39743 |               tempfile
import time:      2005 |       2005 |                 urllib.response
import time:      2326 |       4330 |               urllib.error
import time:     15342 |      59414 |             urllib.request
import time:     30223 |      93291 |           http.cookiejar
import time:     11867 |      11867 |           http.cookies
import time:      1815 |     150561 |         requests.compat
import time:      5215 |     155776 |       requests.exceptions
import time:      1043 |       1043 |       chardet
import time:       942 |        942 |         chardet
import time:      1878 |       1878 |           idna.package_data
import time:      5957 |       5957 |             idna.idnadata
import time:      2088 |       2088 |             idna.intranges
import time:      7224 |      15269 |           idna.core
import time:      3056 |      20202 |         idna
import time:      5150 |      26293 |       requests.packages
import time:      1299 |       1299 |             importlib._abc
import time:      1212 |       2511 |           importlib.util
import time:       801 |        801 |               _winapi
import time:       736 |        736 |               nt
import time:       825 |        825 |               nt
import time:       769 |        769 |               nt
import time:      1089 |       1089 |               nt
import time:       732 |        732 |               nt
import time:      1171 |       6121 |             ntpath
import time:      6533 |      12653 |           pathlib
import time:      6351 |      21513 |         zipfile
import time:      2317 |       2317 |                   importlib.resources.abc
import time:      2872 |       2872 |                   importlib.resources._adapters
import time:      2649 |       7837 |                 importlib.resources._common
import time:      2113 |       2113 |                 importlib.resources._legacy
import time:      1464 |      11412 |               importlib.resources
import time:      1633 |      13045 |             certifi.core
import time:      1486 |      14531 |           certifi
import time:      1054 |      15584 |         requests.certs
import time:      1119 |       1119 |         requests.__version__
import time:      3407 |       3407 |         requests._internal_utils
import time:      2533 |       2533 |         requests.cookies
import time:      1551 |       1551 |         requests.structures
import time:      1904 |       1904 |             importlib.resources._itertools
import time:      2034 |       3937 |           importlib.resources.readers
import time:      1583 |       5519 |         importlib.readers
import time:      4926 |      56150 |       requests.utils
import time:      1662 |       1662 |             requests.auth
import time:      2019 |       2019 |                 stringprep
import time:      2032 |       4051 |               encodings.idna
import time:       955 |        955 |               requests.hooks
import time:      3015 |       3015 |               requests.status_codes
import time:      4086 |      12105 |             requests.models
import time:      1023 |       1023 |               urllib3.contrib
import time:       884 |        884 |               socks
import time:      2356 |       4262 |             urllib3.contrib.socks
import time:      2623 |      20650 |           requests.adapters
import time:      8201 |      28850 |         requests.sessions
import time:      1499 |      30349 |       requests.api
import time:      3185 |     668628 |     requests
import time:      1723 |       1723 |       openmeteo_sdk
import time:       514 |        514 |                 importlib.machinery
import time:      1343 |       1857 |               flatbuffers.compat
import time:      1261 |       3118 |             flatbuffers.packer
import time:      1550 |       1550 |                   numpy._utils._convertions
import time:      1174 |       2724 |                 numpy._utils
import time:      3150 |       5874 |               numpy._globals
import time:      2223 |       2223 |               numpy.exceptions
import time:      1159 |       1159 |               numpy.version
import time:       474 |        474 |                 numpy._distributor_init_local
import time:      1493 |       1966 |               numpy._distributor_init
import time:      1393 |       1393 |                         numpy._utils._inspect
import time:      2207 |       2207 |                           numpy.core._exceptions
import time:      1215 |       1215 |                           numpy.dtypes
import time:     21218 |      24640 |                         numpy.core._multiarray_umath
import time:      2357 |      28389 |                       numpy.core.overrides
import time:      5085 |      33474 |                     numpy.core.multiarray
import time:      1635 |       1635 |                     numpy.core.umath
import time:      2988 |       2988 |                       numbers
import time:      1337 |       1337 |                       numpy.core._string_helpers
import time:       642 |        642 |                             pickle5
import time:      2418 |       2418 |                               _compat_pickle
import time:       947 |        947 |                               _pickle
import time:       899 |        899 |                                   org
import time:       572 |       1470 |                                 org.python
import time:       242 |       1711 |                               org.python.core
import time:      6898 |      11973 |                             pickle
import time:      1884 |      14497 |                           numpy.compat.py3k
import time:      1812 |      16309 |                         numpy.compat
import time:      1389 |       1389 |                         numpy.core._dtype
import time:      3488 |      21186 |                       numpy.core._type_aliases
import time:      3385 |      28894 |                     numpy.core.numerictypes
import time:      1113 |       1113 |                                 _contextvars
import time:      1091 |       2204 |                               contextvars
import time:      1903 |       4107 |                             numpy.core._ufunc_config
import time:      1733 |       5839 |                           numpy.core._methods
import time:     11402 |      17241 |                         numpy.core.fromnumeric
import time:      3164 |      20404 |                       numpy.core.shape_base
import time:      3971 |       3971 |                       numpy.core.arrayprint
import time:      1434 |       1434 |                       numpy.core._asarray
import time:      7508 |      33316 |                     numpy.core.numeric
import time:      7910 |       7910 |                     numpy.core.defchararray
import time:      2600 |       2600 |                     numpy.core.records
import time:      1460 |       1460 |                     numpy.core.memmap
import time:      1803 |       1803 |                     numpy.core.function_base
import time:      1285 |       1285 |                     numpy.core._machar
import time:      2661 |       2661 |                     numpy.core.getlimits
import time:      2163 |       2163 |                     numpy.core.einsumfunc
import time:      1511 |       1511 |                       numpy.core._multiarray_tests
import time:     13621 |      15131 |                     numpy.core._add_newdocs
import time:      4345 |       4345 |                     numpy.core._add_newdocs_scalars
import time:      1218 |       1218 |                     numpy.core._dtype_ctypes
import time:       480 |        480 |                         _ast
import time:      7833 |       8313 |                       ast
import time:      2783 |       2783 |                         _ctypes
import time:      2063 |       2063 |                         ctypes._endian
import time:      7171 |      12016 |                       ctypes
import time:      5432 |      25760 |                     numpy.core._internal
import time:      1658 |       1658 |                     numpy._pytesttester
import time:      7252 |     172557 |                   numpy.core
import time:       245 |     172802 |                 numpy.core._multiarray_umath
import time:      3311 |     176113 |               numpy.__config__
import time:      2031 |       2031 |                 numpy.lib.mixins
import time:      1658 |       1658 |                     numpy.lib.ufunclike
import time:      2942 |       4600 |                   numpy.lib.type_check
import time:      2703 |       7303 |                 numpy.lib.scimath
import time:      1694 |       1694 |                             numpy.lib.stride_tricks
import time:      2841 |       4534 |                           numpy.lib.twodim_base
import time:      2363 |       2363 |                           numpy.linalg._umath_linalg
import time:      1776 |       1776 |                             numpy._typing._nested_sequence
import time:      1010 |       1010 |                             numpy._typing._nbit
import time:      6764 |       6764 |                             numpy._typing._char_codes
import time:      2806 |       2806 |                             numpy._typing._scalars
import time:      1208 |       1208 |                             numpy._typing._shape
import time:     11947 |      11947 |                             numpy._typing._dtype_like
import time:     18340 |      18340 |                             numpy._typing._array_like
import time:      3741 |      47589 |                           numpy._typing
import time:     10433 |      64917 |                         numpy.linalg.linalg
import time:      1537 |      66453 |                       numpy.linalg
import time:      2623 |      69076 |                     numpy.matrixlib.defmatrix
import time:      1536 |      70611 |                   numpy.matrixlib
import time:      2155 |       2155 |                     numpy.lib.histograms
import time:      8678 |      10833 |                   numpy.lib.function_base
import time:      3396 |      84839 |                 numpy.lib.index_tricks
import time:      3430 |       3430 |                 numpy.lib.nanfunctions
import time:      3144 |       3144 |                 numpy.lib.shape_base
import time:      4311 |       4311 |                 numpy.lib.polynomial
import time:     12576 |      12576 |                   platform
import time:      4732 |      17307 |                 numpy.lib.utils
import time:      6775 |       6775 |                 numpy.lib.arraysetops
import time:      1655 |       1655 |                   numpy.lib.format
import time:      1937 |       1937 |                   numpy.lib._datasource
import time:      2452 |       2452 |                   numpy.lib._iotools
import time:      4950 |      10991 |                 numpy.lib.npyio
import time:      1363 |       1363 |                 numpy.lib.arrayterator
import time:      1786 |       1786 |                 numpy.lib.arraypad
import time:      1204 |       1204 |                 numpy.lib._version
import time:      5168 |     149647 |               numpy.lib
import time:      1226 |       1226 |                   numpy.fft._pocketfft_internal
import time:      3495 |       4721 |                 numpy.fft._pocketfft
import time:      1470 |       1470 |                 numpy.fft.helper
import time:      1674 |       7864 |               numpy.fft
import time:      2003 |       2003 |                   numpy.polynomial.polyutils
import time:      3357 |       3357 |                   numpy.polynomial._polybase
import time:      2874 |       8233 |                 numpy.polynomial.polynomial
import time:      2641 |       2641 |                 numpy.polynomial.chebyshev
import time:      2186 |       2186 |                 numpy.polynomial.legendre
import time:      2805 |       2805 |                 numpy.polynomial.hermite
import time:      2623 |       2623 |                 numpy.polynomial.hermite_e
import time:      2399 |       2399 |                 numpy.polynomial.laguerre
import time:      1882 |      22765 |               numpy.polynomial
import time:       649 |        649 |                         backports_abc
import time:      4414 |       5063 |                       numpy.random._common
import time:      1305 |       1305 |                       secrets
import time:      3349 |       9716 |                     numpy.random.bit_generator
import time:      1963 |       1963 |                     numpy.random._bounded_integers
import time:      1722 |       1722 |                     numpy.random._mt19937
import time:      6813 |      20212 |                   numpy.random.mtrand
import time:      2089 |       2089 |                   numpy.random._philox
import time:      2081 |       2081 |                   numpy.random._pcg64
import time:      1879 |       1879 |                   numpy.random._sfc64
import time:      5084 |       5084 |                   numpy.random._generator
import time:      1917 |      33260 |                 numpy.random._pickle
import time:      2185 |      35444 |               numpy.random
import time:      3543 |       3543 |               numpy.ctypeslib
import time:       304 |        304 |                         _opcode
import time:      3553 |       3856 |                       opcode
import time:      5271 |       9126 |                     dis
import time:     14973 |      24099 |                   inspect
import time:     24141 |      48239 |                 numpy.ma.core
import time:     11047 |      11047 |                 numpy.ma.extras
import time:      2422 |      61707 |               numpy.ma
import time:     25857 |     494157 |             numpy
import time:      3411 |     500685 |           flatbuffers.number_types
import time:      2246 |       2246 |           flatbuffers.encode
import time:      4741 |     507671 |         flatbuffers.builder
import time:      1673 |       1673 |         flatbuffers.table
import time:      1072 |       1072 |         flatbuffers._version
import time:      1208 |       1208 |         flatbuffers.util
import time:      2089 |     513711 |       flatbuffers
import time:      1893 |       1893 |         openmeteo_sdk.VariableWithValues
import time:      2549 |       4442 |       openmeteo_sdk.VariablesWithTime
import time:      3823 |     523696 |     openmeteo_sdk.WeatherApiResponse
import time:      2114 |    1272161 |   openmeteo_requests.Client
import time:      2024 |    1275759 | openmeteo_requests
patrick-zippenfenig commented 5 months ago

It looks like this is mostly caused by dependencies numpy, flatbuffers and requests.

Are you sure it takes 30 seconds? The cumulative time is 1.275s

carbon-starlight commented 5 months ago

When I run it from my script, it does. Importing it from Python command line takes way less.

patrick-zippenfenig commented 5 months ago

I don't think I can make a significant contribution to improving install time. The dependencies are necessary. Maybe a different package manager instead of pip could improve installation time for you

patrick-zippenfenig commented 5 months ago

Note: Just to be sure: Check your DNS ;-) Maybe there is an unresponsive name resolver in your system configuration