To run your project on Ubuntu Linux, you'll need to set up a Python environment and install all the dependencies listed in your requirements.txt file. Below is a step-by-step guide to help you get your project up and running.
1. Update System Packages
First, ensure your system packages are up-to-date:
sudo apt update
sudo apt upgrade -y
2. Install Python and Essential Build Tools
You'll need Python 3 and some build tools for compiling packages:
sudo apt install -y python3 python3-pip python3-venv python3-dev build-essential
3. Create a Virtual Environment
It's a good practice to use a virtual environment to isolate your project's dependencies:
python3 -m venv myprojectenv
Replace myprojectenv with the name you prefer for your virtual environment.
4. Activate the Virtual Environment
Activate the environment to start using it:
source myprojectenv/bin/activate
You should see the name of your virtual environment prefixed in your terminal prompt.
5. Upgrade pip
Ensure you have the latest version of pip:
pip install --upgrade pip
6. Install System Dependencies for Python Packages
Some Python packages require additional system libraries:
-
For OpenCV:
sudo apt install -y libsm6 libxext6 libxrender-dev libglib2.0-0
-
For MySQL Support (Flask-MySQLdb):
sudo apt install -y default-libmysqlclient-dev
-
For Pillow (PIL):
sudo apt install -y libjpeg-dev zlib1g-dev
7. Address Version Conflicts in requirements.txt
There are some version conflicts in your requirements.txt file:
numpy==1.16.0 is quite old and may not be compatible with tensorflow==2.15.1, which requires a newer numpy.
six==1.12.0 may cause conflicts with other packages.
Flask==1.1.2 is an older version; you might want to upgrade to Flask==2.0.1 or later.
Updated requirements.txt:
Consider updating some package versions for compatibility:
Flask_WTF==0.14.3
pandas==1.1.5
six>=1.15.0
tensorflow==2.15.1
WTForms_Components==0.10.5
stripe==2.27.0
deepface==0.0.49
Werkzeug>=1.0.1
opencv_contrib_python==4.5.2.54
WTForms==2.3.3
Flask_MySQLdb==0.2.0
Flask>=2.0.1
Flask_Mail==0.9.1
matplotlib==3.3.3
Flask_Cors==3.0.10
numpy>=1.20.0
wget==3.2
python_docx==0.8.10
nltk==3.6.2
coolname==1.1.0
# object_detection might not be available on PyPI
Pillow==8.3.2
Note: The object_detection package may not be directly installable via pip. It's usually part of TensorFlow's Object Detection API, which requires a different setup.
8. Install Python Dependencies
Now, install all the dependencies:
pip install -r requirements.txt
Handling Possible Installation Issues:
-
If you encounter errors with mysqlclient during the installation of Flask-MySQLdb:
sudo apt install -y libmysqlclient-dev
Then retry:
pip install mysqlclient
-
If you have issues with deepface dependencies:
Install missing dependencies manually:
pip install gdown retina-face keras-applications keras-preprocessing
-
For nltk Data:
After installing nltk, you may need to download the data:
python -m nltk.downloader all
9. Set Up Environmental Variables (If Needed)
If your project relies on environment variables (like API keys or database URIs), set them in your terminal session or add them to a .env file if your project uses python-dotenv.
For example:
export FLASK_APP=run.py
export FLASK_ENV=development
export DATABASE_URL='mysql://user:password@localhost/dbname'
10. Initialize Database (If Your Project Uses One)
If your project uses a database, ensure it's installed and running:
-
MySQL:
Install and start MySQL server:
sudo apt install -y mysql-server
sudo service mysql start
Secure your installation:
sudo mysql_secure_installation
Create a database and user for your project:
sudo mysql -u root -p
In the MySQL shell:
CREATE DATABASE your_database_name;
CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON your_database_name.* TO 'your_username'@'localhost';
FLUSH PRIVILEGES;
EXIT;
11. Run the Project
Assuming your project is a Flask application:
flask run
Or, if you have a specific entry point:
python run.py
Replace run.py with the name of your main application script.
12. Test the Application
Open a web browser and navigate to the appropriate URL, typically http://localhost:5000, to see if your application is running correctly.
Additional Tips
- Use a
Procfile or Makefile: For complex projects, consider creating a Procfile or Makefile to simplify running common commands.
- Logging: Implement logging to help debug any issues that arise when running the application.
- Documentation: Ensure your code is well-documented, and consider adding a
README.md with setup instructions for future reference.
Troubleshooting
- Module Not Found Errors: Ensure all dependencies are correctly installed in your virtual environment.
- Version Conflicts: Check for conflicting package versions and adjust as necessary.
Resources
By following these steps, you should be able to set up and run your project on Ubuntu Linux successfully. Remember to adjust package versions as necessary to resolve any compatibility issues.