Skip to content

ModuleNotFoundError: No module named 'numpy' #75

Open
@Umar888

Description

@Umar888

I am building a flutter project and want to use python scripts in my project, this is how i integrated. I will explain step by step:

  • Open Terminal and navigate to my project directory.
  • My project name is python_text. So full project directory path becomes /Users/umarghaffar/StudioProjects/python_text
  • Then I run command, to create environment python3 -m venv venv
  • Then I activated environment by using command . venv/bin/activate
  • I noticed a venv folder was created in my flutter project directory
  • Then I run command pip3 install kivy-ios
  • Then I created a directory in my flutter project named python_libs and navigated to that directory.
  • Then I wanted to install numpy and pillow libraries inside python_libs
  • I run command toolchain build numpy and toolchain build pillow
  • After processing, new folders were created in my flutter project directory, named dist,.cache
  • Then I run command export SERIOUS_PYTHON_IOS_DIST="/Users/umarghaffar/StudioProjects/python_text/python_libs/dist"
  • Then flutter clean and flutter pub get
  • After running the application.
  • I got this error when I run python script
    Traceback (most recent call last): File "/var/mobile/Containers/Data/Application/C4EBBD4C-9A21-4FEF-87ED-A140FC39C6CC/Documents/Python Text-1.0.0-1/app/tf.py", line 2, in <module> import numpy as np ModuleNotFoundError: No module named 'numpy' Python program completed with error.

This is my python code

import os
import numpy as np
from PIL import Image
image_paths_string = os.getenv("IMAGE_PATHS")
result_filename = os.getenv("RESULT_FILENAME")
process_type = os.getenv("PROCESS_TYPE")
if not image_paths_string or not result_filename or not process_type:
    print("Required environment variables are not set.")
    exit(1)
image_paths = image_paths_string.split(",")
results = []
for image_path in image_paths:
    try:
        with Image.open(image_path) as img:
            img_array = np.array(img)
            average_color = np.mean(img_array, axis=(0, 1))
            results.append(f"Image: {image_path}, Average Color: {average_color}")
    except Exception as e:
        results.append(f"Error processing {image_path}: {str(e)}")
with open(result_filename, "w") as f:
    for result in results:
        f.write(result + "\n")

My python is placed in app directory inside flutter project directory. Full Path /Users/umarghaffar/StudioProjects/python_text/app/tf.py

Here is the picture of my directory map
Screenshot 2024-02-22 at 2 34 06 PM

Kindly help me to resolve my issue. Let me know where I am doing wrong

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions