Difference between ‘Directory’ and ‘Python Package’ in PyCharm

When to use Directory over Python Package? You can use “Python Package” when you want to put some modules in there which should be importable. PyCharm will automatically create an __init__.py for the directory. Why not create everything as a Python Package? Not every subdirectory in a project should necessarily be a package. For example … Read more

Relative imports for the trilliоnth time

Script vs. Module Here’s an explanation. The short version is that there is a big difference between directly running a Python file, and importing that file from somewhere else. Just knowing what directory a file is in does not determine what package Python thinks it is in. That depends, additionally, on how you load the … Read more

How to build a source distribution without using setup.py file?

This is a somewhat controversial topic, and the answer for the moment is that there is no one single tool that everyone agrees is the “right way” to build source distributions, nor what that tool would be. You can see a long thread about it on the Python Packaging discourse. I hesitate to give too … Read more

Is requirements.txt still needed when using pyproject.toml?

Quoting myself from here My current assumption is: […] you put your (mostly unpinned) dependencies to pyproject.toml instead of setup.py, so you library can be installed as a dependency of something else without causing much troubles because of issues resolving version constraints. On top of that, for “deployable applications” (for lack of a better term), … Read more

How to list dependencies for a python library without installing? [duplicate]

PyPi provides a JSON endpoint with package metadata: >>> import requests >>> url=”https://pypi.org/pypi/{}/json” >>> json = requests.get(url.format(‘pandas’)).json() >>> json[‘info’][‘requires_dist’] [‘numpy (>=1.9.0)’, ‘pytz (>=2011k)’, ‘python-dateutil (>=2.5.0)’] >>> json[‘info’][‘requires_python’] ‘>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*’ For a specific package version, add an additional version segment to the URL: https://pypi.org/pypi/pandas/0.22.0/json

How do I use a relative path in a Python module when the CWD has changed?

Store the absolute path to the module directory at the very beginning of the module: package_directory = os.path.dirname(os.path.abspath(__file__)) Afterwards, load your resources based on this package_directory: font_file = os.path.join(package_directory, ‘fonts’, ‘myfont.ttf’) And after all, do not modify of process-wide resources like the current working directory. There is never a real need to change the working … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)