question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ImportError in every `dvc command` after `pip install -e` in develop environment

See original GitHub issue

Bug Report

ImportError: cannot import name '__version__' from '_version' (/Users/gao/Code/dvc/dvc/_version.py)

After every dvc command didn’t affect the command running but quite anonying.

Description

Meet this error message after every command.

Traceback (most recent call last):
  File "/Users/gao/Code/dvc/dvc/__main__.py", line 7, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/Users/gao/Code/dvc/dvc/main.py", line 97, in main
    if analytics.is_enabled():
  File "/Users/gao/Code/dvc/dvc/analytics.py", line 50, in is_enabled
    Config(validate=False).get("core", {}).get("analytics", "true")
  File "/Users/gao/Code/dvc/dvc/config.py", line 107, in __init__
    self.load(validate=validate, config=config)
  File "/Users/gao/Code/dvc/dvc/config.py", line 153, in load
    conf = self.load_config_to_level()
  File "/Users/gao/Code/dvc/dvc/config.py", line 278, in load_config_to_level
    merge(merged_conf, self.load_one(merge_level))
  File "/Users/gao/Code/dvc/dvc/config.py", line 202, in load_one
    conf = self._load_config(level)
  File "/Users/gao/Code/dvc/dvc/config.py", line 174, in _load_config
    from configobj import ConfigObj
  File "/Users/gao/anaconda3/envs/dvc/lib/python3.8/site-packages/configobj.py", line 23, in <module>
    from _version import __version__
ImportError: cannot import name '__version__' from '_version' (/Users/gao/Code/dvc/dvc/_version.py)

Reproduce

  1. git clone git@github.com:iterative/dvc.git
  2. cd dvc
  3. pip3 install -e “.[all,tests]”
  4. dvc doctor.

Expected

No error message

Environment information

Output of dvc doctor:

$ dvc doctor
DVC version: 2.8.2.dev35+geb0b4ce6
---------------------------------
Platform: Python 3.8.8 on macOS-10.16-x86_64-i386-64bit
Supports:
	azure (adlfs = 2021.9.1, knack = 0.8.0, azure-identity = 1.5.0),
	gdrive (pydrive2 = 1.9.4),
	gs (gcsfs = 2021.10.1),
	hdfs (fsspec = 2021.10.1, pyarrow = 3.0.0),
	webhdfs (fsspec = 2021.10.1),
	http (aiohttp = 3.7.4.post0, aiohttp-retry = 2.4.5),
	https (aiohttp = 3.7.4.post0, aiohttp-retry = 2.4.5),
	s3 (s3fs = 2021.10.1, boto3 = 1.17.106),
	ssh (sshfs = 2021.9.0),
	oss (ossfs = 2021.8.0),
	webdav (webdav4 = 0.9.3),
	webdavs (webdav4 = 0.9.3)
Cache types: <https://error.dvc.org/no-dvc-cache>
Caches: local
Remotes: oss, https, s3
Workspace directory: apfs on /dev/disk3s1s1
Repo: dvc, git

Additional Information (if any):

Error go out from configobj. It wants to read the contents from https://github.com/DiffSK/configobj/blob/master/src/configobj/_version.py but this file did not install properly.

And, as there is a _version.py generated automatically after pip install -e in our dvc repo. configobj wrongly reads it.

asciicast

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
skshetrycommented, Oct 19, 2021

This also affects the users, as that’s where we store version information. Using _version.py is the recommended practice (https://github.com/pypa/setuptools_scm/issues/575). The workaround is to name the file anything other than _version. Perhaps __version__.py?

1reaction
skshetrycommented, Oct 19, 2021

The issue with _version is due to configobj.

Instead of importing from .version, it’s importing from _version which is conflicting: https://github.com/DiffSK/configobj/blob/9d2aab01c77dce600b296ba9da1163cc0bbc14e0/configobj.py#L23

This has been fixed in it’s master, but it hasn’t had a release for 6 years now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

docs: recommend _version.py · Issue #575 - GitHub
I'm asking since I'd normalized on using version.py everywhere ... ImportError in every dvc command after pip install -e in develop ...
Read more >
Error after upgrading pip: cannot import name 'main'
You can resolve this issue by reinstalling pip. Use one of the following command line commands to reinstall pip:.
Read more >
pip commands fail with ImportError cannot import ... - SUSE
Running that command will work but should not be done, as next zypper update will apply based on previous version installed by zypper....
Read more >
Errors setting up build environment on mac - Copter 4.1
Trying to set up a build environment on my macbook pro 2015 according to the instructions. I successfully reach this step of the...
Read more >
attributeerror: type object 'distribution' has no attribute ...
Hello,. I encounter the following problem after using the command: pip3 install -e ".[test]" -vvv . with setuptools 46.0.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found