Todd
Todd

Reputation: 2999

Copy Python App to a new Machine?

I have a Python app running on windows that has imports for the following packages:

requests json psycopg2

I copy the entire project (I used Pycharms to write the app and import the packages) to a new machine and expected it would work. The new machine is also windows and I'm trying to run my script from the command line (i.e. no Pycharm on the new machine).

Instead, I get an error saying "ModuleNotFoundError: No module named 'requests'"

If I look at the project, I have the directories:

  venv
    Lib
      site-packages
        requests

What am I missing/doing wrong?

Upvotes: 0

Views: 387

Answers (2)

Nicholas Martinez
Nicholas Martinez

Reputation: 586

You have a couple of options here but first the problem. You are exporting your code base to a new machine without the required Modules installed on that machine and/or within your Python project's environment. After you have python installed on your new machine, you need to be sure to point your PyCharm Project to the proper environment.

File > Default Preferences > Project Interpreter

The window that appears on the right will contain a drop down menu labeled Project Interpreter. If you click on the drop down, it should reveal a list of the available Python environments on your machine.

enter image description here

Based on your description of your site-packages directory I would assume you do not have your interpreter pointed the proper environment on your new machine. With that said, you would be better served creating a new virtual python environment on your machine and installing each relevant dependency within that environment.

Take a look at this post here for your first best option on re-creating your old python environment on your new machine.

EDIT: I apologize for not reading the question more thoroughly before answering the questions. If this is running on a Windows machine you will need to double check the environment path python is using. It is very easy to install python at a different PATH than the command line environment is checking on a Windows box. If for example your PATH is pointing to a different version of Python and PIP is installing packages somewhere else this issue can occur. Double check your System PATH for python and which version the command line is running.

Upvotes: 1

J_H
J_H

Reputation: 20450

On the new machine you must source venv/bin/activate so your path environment variables are set properly. In particular, which python should say venv/bin/python rather than /usr/bin/python. Also, take care to conda env update or pip install -r requirements.txt so you'll have suitable venv libraries on the new machine.

Upvotes: 1

Related Questions