0

I am a Java developer that has inherited a Python project. The previous developer didn't leave any info on what IDE was used nor can I see any IDE-related artifacts (e.g. project config files).

This is a program that is already deployed and running in a Linux environment so it works. I will be making enhancements.

It was developed in Python 3.6 and I want to continue using that version until I get the code working locally (Windows 10). At that point, I'll upgrade it to the latest version of Python.

The problem I'm having is I don't know how to ensure that all the 3rd-party modules are included in the environment. How would I go about identifying them?

I have looked at PIP for generating a requirements.txt file but I'm not sure if that's what I need or not. When I run pip freeze > requirements.txt, it just creates an empty file. And I'm not understanding how pip is supposed to know the context of the request. I need it to identify the modules used by the code, if that's possible, but there doesn't seem to be any mechanism for telling pip where the code is.

JimG225
  • 1
  • 2
  • 1
    `pip freeze` outputs the list of dependencies you've _currently_ got installed, it doesn't trawl the codebase for what you _ought to_. – jonrsharpe Jan 30 '23 at 16:41
  • If there's not an existing `requirements.txt` (for `pip`) or `Pipfile` (for `pipenv`) or something similar, your best bet is probably scanning the code for `import` lines, building a unique list, and then weeding out built-in modules (which you could identify by trying to import things in a clean virtual environment). – larsks Jan 30 '23 at 16:42
  • The IDE shouldn't really be important. If the previous maintainer of the code base didn't actually properly package the python project, then there is not great way of doing this other than some form of static analysis of the code and it's imports. even just a text-based search of `import` can get you started, although, it's going to be annoying figuring out which are standard library or which are not if you aren't familiar with Python, although here are various approaches: https://stackoverflow.com/questions/6463918/how-to-get-a-list-of-all-the-python-standard-library-modules – juanpa.arrivillaga Feb 01 '23 at 03:36
  • Thanks for the comment. I started that process by just running the code locally. The first import it fails on is psycopg2. So I ran pip install from the command line, which seemed to run successfully. After I ran that I ran pip freeze and an it showed psycopg2==2.9.5. But when I run the code in the IDE, it still complains that the psycopg2 model is not found. If I run the code from the command line, it does NOT fail on psycopg2 but fails on the next non-standard import. So the IDE is somehow not recognizing that psycopg2 is installed. The IDE is Visual Studio Community edition. – JimG225 Feb 02 '23 at 11:34

0 Answers0