Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'str' object has no attribute 'exists' #1674

Closed
milind-shakya-sp opened this issue Feb 26, 2020 · 6 comments · Fixed by #1676
Closed

AttributeError: 'str' object has no attribute 'exists' #1674

milind-shakya-sp opened this issue Feb 26, 2020 · 6 comments · Fixed by #1676

Comments

@milind-shakya-sp
Copy link

Issue

Describe what's the expected behaviour and what you're observing.
virtualenv throws an attributeerror when
python -m virtualenv venv -ppython3 --with-traceback is run

Environment

Provide at least:

  • OS: Ubuntu bionic
  • pip list of the host python where virtualenv is installed:
apqdirs==1.4.3
aspy.yaml==1.3.0
cached-property==1.5.1
cfgv==3.1.0
distlib==0.3.0
filelock==3.0.12
identify==1.4.11
importlib-metadata==1.5.0
importlib-resources==1.0.2
nodeenv==1.3.5
pre-commit==1.11.1
PyYAML==5.3
six==1.14.0
toml==0.10.0
virtualenv==20.0.7
zipp==3.0.0

Output of the virtual environment creation

Make sure to run the creation with -vvv --with-traceback:
Python: 3.6.8
virtualenv: 20.0.7

python -m virtualenv venv -ppython3 --with-traceback
[2020-02-26T19:04:25.421Z] Traceback (most recent call last):
[2020-02-26T19:04:25.421Z]   File "/opt/Python-3.6.8/lib/python3.6/runpy.py", line 193, in _run_module_as_main
[2020-02-26T19:04:25.421Z]     "_main_", mod_spec)
[2020-02-26T19:04:25.421Z]   File "/opt/Python-3.6.8/lib/python3.6/runpy.py", line 85, in _run_code
[2020-02-26T19:04:25.421Z]     exec(code, run_globals)
[2020-02-26T19:04:25.421Z]   File "/tmp/jenkins---PR-4836-12/precommit/lib/python3.6/site-packages/virtualenv/_main_.py", line 61, i
n <module>
[2020-02-26T19:04:25.421Z]     run_with_catch()
[2020-02-26T19:04:25.421Z]   File "/tmp/jenkins---PR-4836-12/precommit/lib/python3.6/site-packages/virtualenv/_main_.py", line 50, i
n run_with_catch
[2020-02-26T19:04:25.421Z]     run(args, options)
[2020-02-26T19:04:25.421Z]   File "/tmp/jenkins---PR-4836-12/precommit/lib/python3.6/site-packages/virtualenv/_main_.py", line 20, i
n run
[2020-02-26T19:04:25.421Z]     session = cli_run(args, options)
[2020-02-26T19:04:25.421Z]   File "/tmp/jenkins---PR-4836-12/precommit/lib/python3.6/site-packages/virtualenv/run/_init_.py", line 2
7, in cli_run
[2020-02-26T19:04:25.421Z]     session = session_via_cli(args, options)
[2020-02-26T19:04:25.421Z]   File "/tmp/jenkins---PR-4836-12/precommit/lib/python3.6/site-packages/virtualenv/run/_init_.py", line 3
7, in session_via_cli
[2020-02-26T19:04:25.421Z]     creator, seeder, activators = tuple(e.create(parser._options) for e in parser._elements)  # create type
s
[2020-02-26T19:04:25.421Z]   File "/tmp/jenkins---PR-4836-12/precommit/lib/python3.6/site-packages/virtualenv/run/_init_.py", line 3
7, in <genexpr>
[2020-02-26T19:04:25.421Z]     creator, seeder, activators = tuple(e.create(parser._options) for e in parser._elements)  # create type
s
[2020-02-26T19:04:25.421Z]   File "/tmp/jenkins---PR-4836-12/precommit/lib/python3.6/site-packages/virtualenv/run/plugin/seeders.py",
line 31, in create
[2020-02-26T19:04:25.421Z]     return self._impl_class(options)
[2020-02-26T19:04:25.421Z]   File "/tmp/jenkins---PR-4836-12/precommit/lib/python3.6/site-packages/virtualenv/seed/via_app_data/via_ap
p_data.py", line 19, in _init_
[2020-02-26T19:04:25.421Z]     super(FromAppData, self)._init_(options)
[2020-02-26T19:04:25.421Z]   File "/tmp/jenkins---PR-4836-12/precommit/lib/python3.6/site-packages/virtualenv/seed/embed/base_embed.py
", line 21, in _init_
[2020-02-26T19:04:25.421Z]     self.extra_search_dir = [i.resolve() for i in options.extra_search_dir if i.exists()]
[2020-02-26T19:04:25.421Z]   File "/tmp/jenkins---PR-4836-12/precommit/lib/python3.6/site-packages/virtualenv/seed/embed/base_embed.py
", line 21, in <listcomp>
[2020-02-26T19:04:25.421Z]     self.extra_search_dir = [i.resolve() for i in options.extra_search_dir if i.exists()]
[2020-02-26T19:04:25.421Z] AttributeError: 'str' object has no attribute 'exists'
[2020-02-26T19:04:25.421Z] ERROR: InvocationError for command /tmp/jenkins---PR-4836-12/precommit/bin/python -m virtualenv venv -ppyth
on3 --with-traceback (exited with code 1)
[2020-02-26T19:04:25.421Z] ___________________________________ summary ____________________________________
[2020-02-26T19:04:25.421Z] ERROR:   precommit: commands failed
script returned exit code 1
@asottile
Copy link
Contributor

@gaborbernat here's the simplest reproduction:

$ VIRTUALENV_EXTRA_SEARCH_DIR=d virtualenv venv
AttributeError: 'str' object has no attribute 'exists'

@gaborbernat
Copy link
Contributor

Will take a look tomorrow, but feel free to make a pr before 😎

@asottile
Copy link
Contributor

@milind-shakya-sp in the meantime you can probably work around this by unsetting VIRTUALENV_EXTRA_SEARCH_DIR

@asottile
Copy link
Contributor

here's a patch which "fix"es this but feels not the right idea:

diff --git a/src/virtualenv/seed/embed/base_embed.py b/src/virtualenv/seed/embed/base_embed.py
index 98ba65f..b7d6a99 100644
--- a/src/virtualenv/seed/embed/base_embed.py
+++ b/src/virtualenv/seed/embed/base_embed.py
@@ -18,7 +18,7 @@ class BaseEmbed(Seeder):
         super(BaseEmbed, self).__init__(options, enabled=options.no_seed is False)
 
         self.download = options.download
-        self.extra_search_dir = [i.resolve() for i in options.extra_search_dir if i.exists()]
+        self.extra_search_dir = [Path(i).resolve() for i in options.extra_search_dir if Path(i).exists()]
 
         def latest_is_none(key):
             value = getattr(options, key)
@@ -57,7 +57,6 @@ class BaseEmbed(Seeder):
         parser.add_argument(
             "--extra-search-dir",
             metavar="d",
-            type=Path,
             nargs="+",
             help="a path containing wheels the seeder may also use beside bundled (can be set 1+ times)",
             default=[],

gaborbernat added a commit that referenced this issue Feb 27, 2020
Resolves #1674.

Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
@gaborbernat
Copy link
Contributor

@asottile you're right 7649968 is the fix that's lot more complicated

@gaborbernat
Copy link
Contributor

Hello, a fix for this issue has been released via virtualenv 20.0.8; see https://pypi.org/project/virtualenv/20.0.8/ (https://virtualenv.pypa.io/en/latest/changelog.html#v20-0-8-2020-03-04). Please give a try and report back if your issue has not been addressed; if not, please comment here, and we'll reopen the ticket. We want to apologize for the inconvenience this has caused you and say thanks for having patience while we resolve the unexpected bugs with this new major release.
thanks

@pypa pypa locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants