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.

Poetry trips up with a `json.py` or `select.py` or other stdlib names in cwd

See original GitHub issue
  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: Ubuntu 18.04 LTS
  • Poetry version: 0.12.10

Issue

poetry throws exception if theres a module in cwd conflicting with a stdlib one

to reproduce:

mkdir test && cd test
poetry init -n -q
touch json.py  # or {sys,os,platform,select}.py
poetry add requests  # or any poetry command

On Poetry 0.12.5 it raises:

[EnvCommandError]                                                           
Command /home/me/.cache/pypoetry/virtualenvs/test-py3.6/bin/python -c "im  
port json; import os; import platform; import sys; implementation = getattr(sys, 'imple  
mentation', None); iver = '{0.major}.{0.minor}.{0.micro}'.format(implementation.version  
) if implementation else '0'; implementation_name = implementation.name if implementati  
on else ''; env = {'implementation_name': implementation_name,'implementation_version':  
 iver,'os_name': os.name,'platform_machine': platform.machine(),'platform_release': pla  
tform.release(),'platform_system': platform.system(),'platform_version': platform.versi  
on(),'python_full_version': platform.python_version(),'platform_python_implementation':  
 platform.python_implementation(),'python_version': platform.python_version()[:3],'sys_  
platform': sys.platform,'version_info': sys.version_info[:3],};print(json.dumps(env))"                        
errored with the following output:                                                       
Traceback (most recent call last):                                                       
  File "<string>", line 1, in <module>                                                   
AttributeError: module 'json' has no attribute 'dumps'

On 0.12.10:

[JSONDecodeError]             
Expecting value: line 1 column 1 (char 0)

I can see the error comes from executing python -c, copying the command directly on bash, it does raises an exception but adding the -I : isolate Python from the user's environment (implies -E and -s) flag produces the right output.

Although naming top level modules with stdlib names is not best-practice, some names may not be immediately obvious (I was using select.py), and the error output on current poetry version is not helpful (even with -vvv, took me a while to pin down the error)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
naringascommented, Feb 5, 2019

I bumped into a similar error with poetry 0.12.11 on mac os with homebrewed python 3.7

I managed to bypass it by erasing the entire the entire ~/Library/Caches/pypoetry folder and everything in it

0reactions
finswimmercommented, Oct 7, 2020

I agree with @jtrakk. If python will find a module in the current working directory it will prefer it. So there is nothing poetry can do about it here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Commands | Documentation | Poetry - Python dependency ...
This command will help you kickstart your new Python project by creating a ... The --name option is smart enough to detect namespace...
Read more >
Dependency Management With Python Poetry
Learn how Python Poetry will help you start new projects, maintain existing ones, and master dependency management.
Read more >
what feature you want python to have in next update? - Reddit
For Android I finally found something called chaquopy as a way to embed a Python runtime inside android apps, supports Python 3.x.
Read more >
Use `Python -m Pip` - Hacker News
Statically links all the dependencies and the Python interpreter. Other machine can just run the executable, no need to set up a venv+pip....
Read more >
Package List — Spack 0.20.0.dev0 documentation
This is a list of things you can install using Spack. It is automatically generated based on the packages in this Spack version....
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