python - Delete unused packages from requirements file -


is there easy way delete no-more-using packages requirements file?

i wrote bash script task but, doesn't work expected. because, packages not used following pypi project names. example;

dj-database-url 

package used

dj_database_url 

my project has many packages in own requirements file, so, searching them one-by-one messy, error-prone , takes time. searched, ides don't have property, yet.

you can use code inspection in pycharm.

delete contents of requirements.txt keep empty file. load project in, pycharm go code -> inspect code.... choose whole project option in dialog , click ok. in inspection results panel locate package requirements section under python (note section showed if there requirements.txt or setup.py file). section contain 1 of following messages:

  • package requirement '<package>' not satisfied if there package listed in requirements.txt not used in .py file.
  • package '<package>' not listed in project requirements if there package used in .py files, not listed in requirements.txt.

you interested in second inspection. can add used packages requirements.txt right clicking package requirements section , selecting apply fix 'add requirements '<package>' requirements.txt'. note show 1 package name, add used packages requirements.txt if called section.

if want, can add them 1 one, right click inspection corresponding package , choose apply fix 'add requirements '<package>' requirements.txt', repeat each inspection of kind.

after can create clean virtual environment , install packages new requirements.txt.

also note pycharm has import optimisation feature, see optimize imports.... can useful use feature before other steps listed above.

apply fix packages not listed in requirements.txt


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -