Install PyV8 in Ubuntu, and install PyV8 in Ubuntu

Source: Internet
Author: User

Install PyV8 in Ubuntu, and install PyV8 in Ubuntu

In the past few days, PyV8 needs to be used for python and javascript interaction. Previously installed in windows, and directly installed using exe, there is no problem.
As a result, many pitfalls have been encountered during Ubuntu installation, mainly because the methods on the Internet are not feasible and I don't know why. Finally, after a night of hard work, we finally finished.

Install dependency

First install the dependency: Boost. Most of the online tutorials in this step are similar and necessary;

sudo apt-get install sconssudo apt-get install libboost-dev libboost-thread-devsudo apt-get install libboost-system-dev libboost-python-dev

Install PyV8

Most of the tutorials on the Internet use svncheckout to output code for V8 and PyV8, and then set the V8 directory to V8_HOME. Finally, compile PyV8. Do not say whether svn can be used for migration, (I did not move out of the wall anyway) And then I went to google. on the code website, the source code is downloaded, and various errors are generated during the compilation of the results, which cannot be executed at all.

There are also some Tutorials that directly use pip for installation, and various errors are also reported. This is missing.
So I want to directly find the binary file and copy it to the python package directory. The result is still smooth! Finally, it was easy to install.
Binary File googlecode official website, someone on github also provides a very comprehensive binary Installation File https://github.com/emmetio/pyv8-binaries find the version suitable for your machine download.

The decompressed file contains the following two files: one source code and one binary file. Generally, third-party packages in Python have enough of these two files,

PyV8.py

_ PyV8.so
Then copy the two files to the directory of Your python third-party package. For example, mine is:

Cd pyv8 // enter the decompressed directory sudo cp */usr/lib/python2.7/dist-packages/

The following error is reported when you try to import the import PyV8 result:

ImportError: libboost_python_py27.so.1.54.0: cannot open shared object file: No such file or directory
When I saw this error, I thought that I had installed the dependency before. Why did I still report this error.
I roughly checked some of them for the link library path settings, and then checked libboost_python_py27.so.1.54.0.

Shomy @ LiuPC: blog $ find/usr/lib/-name libboost_python-py27.so.1.54.0
/Usr/lib/x86_64-linux-gnu/libboost_python-py27.so.1.54.0

Sure enough, there is a link library. Why can't it be detected? The problem lies in the environment variable LD_LIBRARY_PATH, because python searches for the link library from this path.

However, I have no echo $ LD_LIBRARY_PATH, but I just need to add the above path to the environment variable. -- Add a line at the end of. bashrc: (the path may be inconsistent. Please add it according to your actual situation)

Export LD_LIBRARY_PATH = $ LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu
Save and exit, and then use source ~ /. Just reload bashrc. Again, import PyV8 is normal!

Run the following test code:

import PyV8ctxt = PyV8.JSContext()ctxt.enter()func = ctxt.eval("""  (function(){    function hello(){      return "Hello world.";    }    return hello();  })""")print func()

Run the Hello World command to verify that the installation is successful. You can simulate logon ~~~

Articles you may be interested in:
  • Ubuntu lighttpd + webpy (fastcgi) configuration method
  • How to configure vim on ubuntu 15.10 In Python Development
  • Install the Python GUI tool wxPython in Ubuntu

Related Article

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.