8

I moved my python project from a native Linux installation to Windows and I tried to run pipenv custom scripts through WSL 2 on Windows 10 using pipenv run my_script. Although the same command works in a native Ubuntu installation, on WSL 2 (Ubuntu 20.04) I get an Attribute error in the shlex module regarding the instream object not having attribute read.

My [scripts] section in the Pipfile looks like this, but I've also tried running python scripts (instead of shell ones) and the error can be reproduced with any custom script.

[scripts]
build = "bash ./scripts/main.sh -b"
analyze = "bash ./scripts/main.sh -a"

I've also tried to update the pipenv package but looks like I'm running the latest version (11.9.0, pipenv-2020.6.2).

My code doesn't seem to run at all since I get an error before the arguments are passed to the custom script. This is the stacktrace I get from running the command:

Traceback (most recent call last):
File "/usr/bin/pipenv", line 11, in <module>
  load_entry_point('pipenv==11.9.0', 'console_scripts', 'pipenv')()
File "/usr/lib/python3/dist-packages/pipenv/vendor/click/core.py", line 722, in __call__
  return self.main(*args, **kwargs)
File "/usr/lib/python3/dist-packages/pipenv/vendor/click/core.py", line 697, in main
  rv = self.invoke(ctx)
File "/usr/lib/python3/dist-packages/pipenv/vendor/click/core.py", line 1066, in invoke
  return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/lib/python3/dist-packages/pipenv/vendor/click/core.py", line 895, in invoke
  return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3/dist-packages/pipenv/vendor/click/core.py", line 535, in invoke
  return callback(*args, **kwargs)
File "/usr/lib/python3/dist-packages/pipenv/cli.py", line 602, in run
  core.do_run(command=command, args=args, three=three, python=python)
File "/usr/lib/python3/dist-packages/pipenv/core.py", line 2200, in do_run
  command = ' '.join(project.scripts[command])
File "/usr/lib/python3/dist-packages/pipenv/project.py", line 374, in scripts
  scripts[k] = shlex.split(v, posix=True)
File "/usr/lib/python3.8/shlex.py", line 311, in split
  return list(lex)
File "/usr/lib/python3.8/shlex.py", line 300, in __next__
  token = self.get_token()
File "/usr/lib/python3.8/shlex.py", line 109, in get_token
  raw = self.read_token()
File "/usr/lib/python3.8/shlex.py", line 140, in read_token
  nextchar = self.instream.read(1)
AttributeError: 'list' object has no attribute 'read'
marinoandrea
  • 81
  • 1
  • 7
  • I encountered it on Raspbian as well. It seems to be a bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=945139 Right now as a workaround, I use `makefile` instead. – Fanchen Bao Aug 04 '20 at 23:16
  • 4
    Just resolved this on my Raspbian by uninstalling `pipenv` via `sudo apt-get remove pipenv`, and reinstall with `pip3 install pipenv`. Maybe this will resolve your issue as well. – Fanchen Bao Aug 05 '20 at 18:39
  • 3
    @FanchenBao thank you, I've now installed pipenv with pip and use it as a python module with `python3 -m pipenv`, this works with no issues. I still don't know what's going on with the apt package though. – marinoandrea Aug 06 '20 at 08:09
  • Same problem, using Ubuntu 20.04 in WSL2. Using `pip3 install pipenv` and `python3 -m pipenv` fixed it. – Pat Mar 22 '21 at 18:15

0 Answers0