Automatically create file ‘requirements.txt’

You can use the following code to generate a requirements.txt file: pip install pipreqs pipreqs /path/to/project The benefits of using pipreqs from its GitHub. Why not pip freeze? pip freeze only saves the packages that are installed with pip install in your environment. pip freeze saves all packages in the environment including those that you … Read more

python: Two modules and classes with the same name under different packages

You want to import the User modules in the package __init__.py files to make them available as attributes. So in both Helper/__init_.py and Controller/__init__.py add: from . import User This makes the module an attribute of the package and you can now refer to it as such. Alternatively, you’d have to import the modules themselves … Read more

How do I import module in jupyter notebook directory into notebooks in lower directories? [duplicate]

You need to make sure that the parent directory of new_module is on your python path. For a notebook that is one level below new_module, this code will do the trick: import os import sys nb_dir = os.path.split(os.getcwd())[0] if nb_dir not in sys.path: sys.path.append(nb_dir) If you’re further down in the directory hierarchy, you will need … Read more

ImportError: No module named ‘flask.ext’ [duplicate]

The “flask.ext” style of naming/importing modules has been deprecated since 2016. Here’s the reasoning. You should use the first style you described instead: # Use this import format from flask_sqlalchemy import SQLAlchemy As for the suggestion that you install your flask packages globally, this somewhat defeats the purpose of using a venv in the first … Read more

‘Attempted relative import in non-package’ although packages with __init__.py in one directory

Relative imports only work for packages, but when you importing in extended.py you are running a top-level module instead. The current directory may hold a __init__.py file but that doesn’t make exended.py part of a package yet. For something to be considered a package, you need to import the directory name instead. The following would … Read more

How to locally develop a python package?

The easiest way to do such testing would be to create a virtual environment, and then installing the package in development mode. Assuming you are on Linux it would look something like this. $ virtualenv dev_env $ source dev_env/bin/activate $ cd ~/project_folder $ pip install -e . This workflow would not overwrite the already installed … Read more

Force python to use an older version of module (than what I have installed now)

A better version of option B. would be to replace import twisted by import pkg_resources pkg_resources.require(“Twisted==8.2.0”) import twisted which will arrange for the correct version of twisted to be imported, so long as it’s installed, and raises an exception otherwise. This is a more portable solution. This won’t work, though (nor would any other variaton … Read more

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