hello all (Please i work in Python and this error appears Can anyone solve this error as this image shows)

 

Please i work in Python and this error appears 

Can anyone solve this error as this image shows

error


hello all

please can any one help me 

for tis error appear when run simple code in python script in metatreder 5

(2023.11.23 16:19:14.975 Python 'c2': python process thread create error [The system cannot find the file specified. (2)]) 
Files:
c2.py  1 kb
 

Try.

# Copyright 2023 Open source testdebug script .
# https://www.mql5.com

import MetaTrader5 as mt5
import tensorflow as tf
from datetime import datetime
import numpy as np
import matplotlib.pyplot as plt

# Log file path
log_file_path = "C:\\Logs\\python_script_log.txt"

# Function to log messages
def log_message(message):
    with open(log_file_path, "a") as log_file:
        log_file.write(f"{datetime.now()} - {message}\n")

try:
    log_message("Script started.")

    # Initialize MetaTrader 5
    if not mt5.initialize():
        log_message("Failed to initialize MetaTrader 5.")
        mt5.shutdown()

    # TensorFlow and other script logic
    printf("ff")  # Assuming printf is a custom function, otherwise use print()
    log_message("Script executed successfully.")

except Exception as e:
    log_message(f"Error: {e}")

finally:
    # Shutdown MetaTrader 5
    mt5.shutdown()
    log_message("MetaTrader 5 shutdown.")

# End of the script

Improperly formatted code edited by moderator.

Script includes a log file ( python_script_log.txt ) to store information about the script's execution. The log_message function is used to write messages to the log file. Any exceptions that occur during script execution will be logged, providing information about the error.

The user can then check the log file ( C:\Logs\python_script_log.txt ) after running the script to see detailed information about each step and any errors encountered. This should help in debugging the issue.

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2023.11.24
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
@Mikkoli #:Try.

Improperly formatted code edited by moderator.

Script includes a log file ( python_script_log.txt ) to store information about the script's execution. The log_message function is used to write messages to the log file. Any exceptions that occur during script execution will be logged, providing information about the error.

The user can then check the log file ( C:\Logs\python_script_log.txt ) after running the script to see detailed information about each step and any errors encountered. This should help in debugging the issue.

Please use the CODE button (Alt-S) when inserting code.

Code button in editor

 
Fernando Carreiro #:

Please use the CODE button (Alt-S) when inserting code.

Not able to import mt5

    import MetaTrader5 as mt5

i use version \Python3.8

when run compiler the error appear  

ImportError: DLL load failed while importing _core: The specified module could not be found. in '__init__.py' (258,0)

 
Mikkoli #:

Try.

Improperly formatted code edited by moderator.

Script includes a log file ( python_script_log.txt ) to store information about the script's execution. The log_message function is used to write messages to the log file. Any exceptions that occur during script execution will be logged, providing information about the error.

The user can then check the log file ( C:\Logs\python_script_log.txt ) after running the script to see detailed information about each step and any errors encountered. This should help in debugging the issue.

Not able to import mt5

    import MetaTrader5 as mt5

i use version \Python3.8

when run compiler the error appear  

ImportError: DLL load failed while importing _core: The specified module could not be found. in '__init__.py' (258,0)


I installed all python (3.5 /3.10/3.8....)  I entered the settings to determine the path (option>path of metaeditor 5) for python The error appeared in every execution process, the same as the  the picture. attach if any one  have solution please for this case?

# Copyright 2022, MetaQuotes Ltd.

# https://www.mql5.com

import MetaTrader5 as mt5

mt5.initialize()

# you code here

# 

mt5.shutdown()
Improperly formatted code edited by moderator.
MQL5.community - User Memo
MQL5.community - User Memo
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
Files:
 

Instead of running Python in MetaEditor/MetaTrader, please try running it externally directly.

First fix the Python issues that are beyond the scope of this forum.

Also, remember to activate Python API Integration in MetaTrader.

 
Fernando Carreiro #:

Instead of running Python in MetaEditor/MetaTrader, please try running it externally directly.

First fix the Python issues that are beyond the scope of this forum.

Also, remember to activate Python API Integration in MetaTrader.

I make this choice

 same error apeare 

 
Db Orc #: I make this choice. same error apeare 
You missed the most important point — run the Python application externally and then resolved the Python issues first.
 
Fernando Carreiro #:
You missed the most important point — run the Python application externally and then resolved the Python issues first.
Sorry sir 
I make this point but same problem 
I think no any answer 
Mey be delete all application and format lab 

 
Please if any one have solve how can import meta trader 5 with python script
Step by setp 
Please send me 
 
Db Orc #:
Please if any one have solve how can import meta trader 5 with python script
Step by setp 
Please send me 

You need to pinpoint the exact reason and this will be wery tricky and you will have to try to record the functions of every file. Try to start with that. Iam not sure wich files are included inside the mt5 in the process . But you can try a debug script . 

You can try by working your way in fallowing manner .

Setup external envirments around all functions all files observer record anything that moves in the filesystem. 

Wish i had more sourcecodes. 


  1. log_message function:

    • This function takes a message as input and appends it to a file named error_log.txt . It is used to log information and errors during script execution.
  2. check_python_version function:

    • Checks the Python version and logs the version information.
    • Verifies that the Python version is compatible (Python 3.6 or later) and logs an error message if it's not.
  3. check_meta_trader_integration function:

    • Attempts to initialize the MetaTrader API ( mt5.initialize() ) and immediately shuts it down ( mt5.shutdown() ).
    • Logs information about the MetaTrader API integration status.
    • If there's an error during initialization, it logs the error and suggests enabling Python API Integration in MetaTrader.
  4. check_required_packages function:

    • Checks for the existence and version of required Python packages ( MetaTrader5 , numpy , tensorflow , matplotlib ).
    • Logs information about each package, including its version.
    • If a required package is not installed, it logs an error message and returns False .
  5. run_sample_process function:

    • Simulates running a sample process (in this case, it tries to divide by zero to generate an error for testing).
    • Logs the result of the sample process.
    • If there's an error during the sample process, it logs the error and suggests checking the code.
  6. Main Block ( if __name__ == "__main__": ):

    • Clears the existing error_log.txt file.
    • Calls the functions sequentially to perform checks and log information.
    • If any check fails (returns False ), the script exits early to prevent further execution.
    • The script concludes by logging a message indicating the completion of script execution.

This script is designed to be a diagnostic tool to check various aspects such as Python version, MetaTrader API integration, required package installations, and the execution of a sample process. It logs information and errors to a file ( error_log.txt ) for later analysis. Adjustments can be made based on specific requirements and the environment in which it is used.

...

Improperly formatted code removed by moderator. Please EDIT your post and use the CODE button (Alt-S) when inserting code.

Code button in editor

Hover your mouse over your post and select "edit" ... 

...