A series of problems and solutions that Java calls Python

Source: Internet
Author: User
First of all, Baidu has a few methods 1, with Jython in a jar package, Jython.jar, which encapsulates a special call Python class, but do not know why I use Java a call on the error, so give up. 2. Use Runtime.getruntime (). EXEC (' python filename ') process to execute Python files, but because your computer has both Python2 installed and Python3 installed, and Python2 is the default call, So runtime execution by default with Python2 run, and I am writing with Python3 code, so it does not work 3, because in the DOS command line interface can switch the work path directly to the Python3 installation directory, and then run the Python3 program, So write a bat batch file to switch directories and run the Python3 file, and then use the Java runtime to invoke the bat batch file, it is important to note that because the Python3 installation directory and Python3 code files in the same directory, So the path in the code needs to use the absolute path, at this point, solve the problem.

A series of problems and solutions that Java calls Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.