'EnvironmentError [Errno 39] “Directory not empty” while generating distribution archives in python

When generating a built distribution archive for my own python package using

python setup.py bdist_wheel

(following the Packaging Python Projects Tutorial) - the following error occured:

running bdist_wheel
running build
running build_py
installing to build/bdist.linux-x86_64/wheel
running install
running install_lib
copying build/lib/deepnog/models/__init__.py -> build/bdist.linux-x86_64/wheel/deepnog/models
running install_egg_info
running egg_info
writing DeepNOG.egg-info/PKG-INFO
writing dependency_links to DeepNOG.egg-info/dependency_links.txt
writing top-level names to DeepNOG.egg-info/top_level.txt
reading manifest file 'DeepNOG.egg-info/SOURCES.txt'
writing manifest file 'DeepNOG.egg-info/SOURCES.txt'
removing 'build/bdist.linux-x86_64/wheel/DeepNOG-0.1.0-py3.7.egg-info' (and everything under it)
Copying DeepNOG.egg-info to build/bdist.linux-x86_64/wheel/DeepNOG-0.1.0-py3.7.egg-info
running install_scripts
adding license file "LICENSE" (matched pattern "LICEN[CS]E*")
error: [Errno 39] Directory not empty: 'build/bdist.linux-x86_64/wheel/DeepNOG-0.1.0-py3.7.egg-info'

I could not find the exact problem described on stack-overflow (as well as only unresolved github issues elsewhere). Therefore I am posting here both the question and answer. A very similar problem occuring in a different context is described and answered here which led me to resolve my issue.



Solution 1:[1]

Problem was resolved once I closed all open files of the package I wanted to generate a built distribution from (i.e. I closed my text-editor).

Solution 2:[2]

Change the Python interpreter you're using to the default. I solved mine by using the default python interpreter rather than the project's interpreter.

You can do this in VS Code by navigating to the view>>command palette>>Python: Select Interpreter and choose the default environment or the created virtual environment you are using.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 saper0
Solution 2