Coder Social home page Coder Social logo

'import param' fails: ImportError: cannot import name '__version__' from 'param._version' (/usr/local/lib/python3.9/site-packages/param/_version.py) about param HOT 13 CLOSED

yurivict avatar yurivict commented on June 1, 2024
'import param' fails: ImportError: cannot import name '__version__' from 'param._version' (/usr/local/lib/python3.9/site-packages/param/_version.py)

from param.

Comments (13)

maximlt avatar maximlt commented on June 1, 2024 1

Feel free to have a look at #903 :)
We plan to release 2.0.2 soon, it's very likely it'll include this fix.

from param.

Hoxbro avatar Hoxbro commented on June 1, 2024

How did you install param? It looks like it was done with a Linux distribution, which did not package the _version file.

from param.

yurivict avatar yurivict commented on June 1, 2024

param was built and installed using the PEP517-compliant build and install projects within the FreeBSD ports framework.

from param.

maximlt avatar maximlt commented on June 1, 2024

Hi @yurivict, you mention the install project, is it thin one https://pypi.org/project/install/?

I've just tried the following with success:

  • Clone the repo and cd into it
  • python3 -m venv .venv and source .venv/bin/activate
  • python -m build
  • pip install dist/param-2.0.2.dev2+g3e90912-py3-none-any.whl
  • mkdir foo && cd foo
  • Run the Python interpreter and import param

Could you please report the exact steps that lead you to the error you reported?

from param.

yurivict avatar yurivict commented on June 1, 2024

Here is the log.

from param.

maximlt avatar maximlt commented on June 1, 2024

Thanks @yurivict, but I'm still confused by this issue.

I've tried to reproduce locally some of the steps you shared in this log file (get sdist, install build/installer/hatchling/hatch-vcs, isolated wheel build, wheel installed with installer) and could import param without any issue.

Coming back to your traceback, it clearly shows that the param/_version.py module exists (otherwise you would see a ModuleNotFoundError) but that it does not contain a __version__ variable, resulting in an ImportError. However, I can confirm that the sdist on PyPI has a __version__ variable in the param/_version.py module:

❯ curl -sL "https://files.pythonhosted.org/packages/14/c8/b42882ed1ba40478d5c1daa6fbb953c8180ea69fe94b9e6783060f5564ae/param-2.0.1.tar.gz" | tar -xzO "param-2.0.1/param/_version.py"
# file generated by setuptools_scm
# don't change, don't track in version control
TYPE_CHECKING = False
if TYPE_CHECKING:
    from typing import Tuple, Union
    VERSION_TUPLE = Tuple[Union[int, str], ...]
else:
    VERSION_TUPLE = object

version: str
__version__: str
__version_tuple__: VERSION_TUPLE
version_tuple: VERSION_TUPLE

__version__ = version = '2.0.1'
__version_tuple__ = version_tuple = (2, 0, 1)

Maybe you could check the content of param/_version.py in your pipeline?

from param.

maximlt avatar maximlt commented on June 1, 2024

Oh wait wait wait, I think I know, do you download param-2.0.1.tar.gz from Github?

from param.

yurivict avatar yurivict commented on June 1, 2024

Oh wait wait wait, I think I know, do you download param-2.0.1.tar.gz from Github?

No, the tarball is downloaded from the PYPI site: https://pypi.org/packages/source/p/param/param-2.0.1.tar.gz

from param.

maximlt avatar maximlt commented on June 1, 2024

Ok ok. I'm at a loss there :/ Really wish I could unblock you. I'd be curious to see the content of param._version.py at different stages of your pipeline.

from param.

yurivict avatar yurivict commented on June 1, 2024

Before build:

$ cat ./work-py39/param-2.0.1/param/_version.py
# file generated by setuptools_scm
# don't change, don't track in version control
TYPE_CHECKING = False
if TYPE_CHECKING:
    from typing import Tuple, Union
    VERSION_TUPLE = Tuple[Union[int, str], ...]
else:
    VERSION_TUPLE = object

version: str
__version__: str
__version_tuple__: VERSION_TUPLE
version_tuple: VERSION_TUPLE

__version__ = version = '2.0.1'
__version_tuple__ = version_tuple = (2, 0, 1)

After build:

$ cat ./work-py39/param-2.0.1/param/_version.py
# coding: utf-8
# file generated by setuptools_scm
# don't change, don't track in version control
version = '2.0.1'
version_tuple = (2, 0, 1)

from param.

yurivict avatar yurivict commented on June 1, 2024

py39-setuptools_scm-6.4.2 is used.

from param.

yurivict avatar yurivict commented on June 1, 2024

The latest is setuptools-scm 8.0.4, but it wasn't yet adopted.

Now I vaguely remember that a similar problem happened with some other port because setuptools-scm was 6.x, and they had to patch the project in some way because setuptools-scm changed behavior between versions.

from param.

maximlt avatar maximlt commented on June 1, 2024

Indeed __version__ was added in _version.py to setuptools-scm in version 7.0.0 (part of this massive PR https://github.com/pypa/setuptools_scm/pull/580/files#diff-bdefa0298003efada7c465428643cc6d9c129168afb3eb5c551b40fcc77feac1R42).

To add compatibility to older versions of setuptools-scm it seems we could try to import version if importing __version__ fails. I also see in their docs they suggest using:

from importlib.metadata import version, PackageNotFoundError

try:
    __version__ = version("package-name")
except PackageNotFoundError:
    # package is not installed
    pass

from param.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.