Installing DBI / DBD-Oracle with ActivePerl

本文介绍如何使用ActivePerl安装DBI/DBD-Oracle,并提供了一个用于测试安装是否成功的Perl脚本示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Installing DBI / DBD-Oracle with ActivePerl

by Jeff Hunter, Sr. Database Administrator

Overview

 

This article provides an overview on the steps required to install ActivePerl and DBI/DBD-Oracle (using Perl Package Manager). Also included in this article is a short Perl program that can be used to test the DBI/DBD installation with an Oracle database.

Download and Install ActivePerl

 

To start, you need to download a copy of ActivePerl. At the time of this writing, the highest release of ActivePerl is 5.8.3 (build 809), but there is no DBD-Oracle package for this release, and you will therefore need to download and install ActivePerl release 5.6.1.

NOTE: Until a DBD package is created for ActivePerl release 5.8.3, you will need to download the ActivePerl 5.6.1 (build 635) release.

You can download ActivePerl from the following location:

http://www.activestate.com/Products/Download/Download.plex?id=ActivePerl

NOTE: It is recommended that you use the MSI installer to install ActivePerl. The Windows AS Package provides NO uninstall functionality, and is recommended only if you are unable to install ActivePerl using the MSI installer.

The installation process for ActivePerl is a very straighforward process as long as you already have the "Windows Installer" service software installed. This service allows you to install, repair, and remove software according to instructions contained in .MSI files. To start the installation process, simply click the downloaded MSI file for ActivePerl: "ActivePerl-5.6.1.635-MSWin32-x86.msi" and follow the screen instructions.

For the purpose of this document, it is assumed that I installed ActivePerl in the directory: C:/Perl.

Download and Install DBI / DBD-Oracle

 

After successfully installing ActivePerl, it is time to download and install the DBI and DBD-Oracle packages using the Perl Package Manager (PPM) application. First, download the version of DBI and DBD-Oracle packages for the release of ActivePerl we are using: 5.6.1 from the following location:

http://ppm.activestate.com/PPMPackages/zips/

Download the two PPM Packages and put them in a temporary directory (i.e. C:/temp):

Once you have the two files into a temporary directory, unzip them:

C:/temp> unzip DBI-1.37.zip
C:/temp> unzip DBD-Oracle.zip
To install each of the packages, simply use the Perl Package Manager (PPM) application.

NOTE: You must install DBI BEFORE installing Oracle DBD !!!!

Installing DBI

 

C:/temp> ppm install DBI.ppd
Installing DBD

 

C:/temp> ppm install DBD-Oracle.ppd

Perl / Oracle Test Application

 

   Sample Oracle DBI Script. testDBDOracle_windows.pl
#!/usr/local/bin/perl

# +----------------------------------------------------------------------+
# | FILE         : testDBDOracle_windows.pl                              |
# | AUTHOR       : Jeff Hunter, Senior Database Administrator            |
# | PURPOSE      : This script will test the DBI/DBD installation.       |
# | OUTPUT FILES : NONE                                                  |
# +----------------------------------------------------------------------+

require "ctime.pl";
require "flush.pl";

use DBI;

&declareGlobalVariables;

&printHeader;

$dbh = &getOracleLogin("$ORACLE_SID", "$ORACLE_USERID", "$ORACLE_PASSWORD");
$dbh->{LongReadLen} = 64000;

&performTest;

&logoffOracle($dbh);

&printFooter;

exit;

# +--------------+
# | SUB ROUTINES |
# +--------------+
sub declareGlobalVariables {

  $ORACLE_SID              = "JEFFDB";
  $ORACLE_USERID           = "system";
  $ORACLE_PASSWORD         = "manager";

  $ENV{'ORACLE_SID'}       = "$ORACLE_SID";
  $ENV{'ORACLE_HOME'}      = "c://oracle//ora92";

}

sub printHeader {

  print "/n";
  print "Running testDBDOracle_windows.pl.../n";
  print "/n";

}

sub printFooter {

  print "Ending testDBDOracle_windows.pl.../n";
  print "/n";

}

sub getOracleLogin {

  local ($oracle_sid, $username, $password) = @_;
  local ($temp_dbh);
  local($tempID, $tempPassword, $tempKey);

  print "  (*) Attempting Oracle Login .../n";


  unless ( $temp_dbh = DBI->connect("dbi:Oracle:$oracle_sid", "$username", $password, {AutoCommit => 0}) ) {
    &programError("Oracle Login Failed as $username", "", "$DBI::errstr", "dba", "jhunter-pager");
    exit;
  }

  print "      OK/n/n";

  return $temp_dbh;

}

sub logoffOracle {

  ($dbh) = @_;

  print "  (*) Attempting Oracle Logoff .../n";

  unless ($dbh->disconnect) {

    # &programError("Could not disconnect from Oracle", "", "$DBI::errstr", "dba", "jhunter-pager");
    # exit;

    # Commented out this section because of the errors we get: ORA-02050
    # (some remote DBs may be in doubt (DBD: disconnect error)

    1;
  }

  print "      OK/n/n";

}

sub performTest {

  local ($rows1, $rows2, $rows3, $rows4);
  local ($test_dbi_intr_no, $test_dbi_name);
  local ($user, $sysdate);

  # +-----------------------+
  # | CREATE TABLE test_dbi |
  # +-----------------------+

  print "  (*) Creating table TEST_DBI .../n";

  $sql_statement = "
    CREATE TABLE test_dbi (
        test_dbi_intr_no    NUMBER(15)
      , test_dbi_name       VARCHAR2(100)
    )
  ";
  unless ($rows = $dbh->do("$sql_statement")) {
    &programError("Could not create table TEST_DBI", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  print "      OK/n/n";

  # +----------------------------+
  # | INSERT INTO TABLE test_dbi |
  # +----------------------------+

  print "  (*) Insert into TEST_DBI .../n";

  $sql_statement = "
    INSERT INTO test_dbi (
        test_dbi_intr_no
      , test_dbi_name
    ) VALUES (
        1000
      , 'Jeff Hunter'
    ) 
  ";

  unless ($rows1 = $dbh->do("$sql_statement")) {
    &programError("Could not do INSERT_TEST_DBI (Jeff) cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  print "      $rows1 rows inserted./n";

  $sql_statement = "
    INSERT INTO test_dbi (
        test_dbi_intr_no
      , test_dbi_name
    ) VALUES (
        1001
      , 'Melody Hunter'
    ) 
  ";

  unless ($rows2 = $dbh->do("$sql_statement")) {
    &programError("Could not do INSERT_TEST_DBI (Melody) cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  print "      $rows2 rows inserted./n";

  $sql_statement = "
    INSERT INTO test_dbi (
        test_dbi_intr_no
      , test_dbi_name
    ) VALUES (
        1002
      , 'Alex Hunter'
    ) 
  ";

  unless ($rows3 = $dbh->do("$sql_statement")) {
    &programError("Could not do INSERT_TEST_DBI (Alex) cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  print "      $rows3 rows inserted./n";

  unless ($dbh->commit) {
    &programError("Could not commit INSERT_TEST_DBI transaction", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  print "      OK/n/n";

  # +----------------------------+
  # | SELECT FROM TABLE test_dbi |
  # +----------------------------+

  print "  (*) Select from TEST_DBI .../n";

  $sql_statement = "
    SELECT
        test_dbi_intr_no
      , test_dbi_name
    FROM
        test_dbi
  ";

  unless ($cursor = $dbh->prepare("$sql_statement")) {
    &programError("Could not prepare SELECT_TEST_DBI cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  unless ($cursor->execute) {
   &programError("Could not execute SELECT_TEST_DBI cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
   $dbh->rollback;
   &logoffOracle($dbh);
   exit;
  }


  while ((   $test_dbi_intr_no
           , $test_dbi_name) = $cursor->fetchrow_array) {

    print "/n";
    print "        --> TEST_DBI_INTR_NO :  $test_dbi_intr_no/n";
    print "        --> TEST_DBI_NAME    :  $test_dbi_name/n";
    print "/n";

  }

  unless ($cursor->finish) {
   &programError("Could not finish SELECT_TEST_DBI cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
   $dbh->rollback;
   &logoffOracle($dbh);
   exit;
  }


  print "      OK/n/n";


  # +----------------------------+
  # | DELETE FROM TABLE test_dbi |
  # +----------------------------+

  print "  (*) Delete from TEST_DBI .../n";

  $sql_statement = "
    DELETE FROM test_dbi
  ";

  unless ($rows4 = $dbh->do("$sql_statement")) {
    &programError("Could not do DELETE_TEST_DBI (All Names) cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  print "      $rows4 rows deleted./n";

  unless ($dbh->commit) {
    &programError("Could not commit DELETE_TEST_DBI transaction", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  print "      OK/n/n";


  # +---------------------+
  # | DROP TABLE test_dbi |
  # +---------------------+

  print "  (*) Drop table TEST_DBI .../n";

  $sql_statement = "
    DROP TABLE test_dbi
  ";

  unless ($rows = $dbh->do("$sql_statement")) {
    &programError("Could not drop table TEST_DBI", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  print "      OK/n/n";


  # +-------------------+
  # | GET USER and DATE |
  # +-------------------+

  print "  (*) Select USER and SYSTEM .../n";

  $sql_statement = "
    SELECT
        user
      , TO_CHAR(sysdate, 'DD-MON-YYYY HH24:MI:SS')
    FROM
        dual
  ";

  unless ($cursor = $dbh->prepare("$sql_statement")) {
    &programError("Could not prepare SELECT_SINGLE cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
    $dbh->rollback;
    &logoffOracle($dbh);
    exit;
  }

  unless ($cursor->execute) {
   &programError("Could not execute SELECT_SINGLE cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
   $dbh->rollback;
   &logoffOracle($dbh);
   exit;
  }


  ($user, $sysdate) = $cursor->fetchrow_array;

  print "/n";
  print "        --> USER             :  $user/n";
  print "        --> SYSDATE          :  $sysdate/n";
  print "/n";

  unless ($cursor->finish) {
   &programError("Could not finish SELECT_SINGLE cursor", "$sql_statement", "$DBI::errstr", "dba", "jhunter-pager");
   $dbh->rollback;
   &logoffOracle($dbh);
   exit;
  }

  print "      OK/n/n";

}


sub programError {

  local($message, $sql_statement, $ora_errstr, $email_who, $page_who) = @_;

  print "+--------------------------+/n";
  print "| SUB: programError        |/n";
  print "+--------------------------+/n";
  print "/n";

  unless($message) {$message = "No message provided from calling module.";}

  print "+-------------------------------------------------------+/n";
  print "| ******************* PROGRAM ERROR ******************* |/n";
  print "+-------------------------------------------------------+/n";
  print "/n";
  print "/n";
  print "Message:/n";
  print "--------------------------------------------------------/n";
  print "$message/n";
  print "/n";
  if ($sql_statement) {
    print "SQL:/n";
    print "--------------------------------------------------------/n";
    print "$sql_statement/n";
    print "/n";
  }

  if ($ora_errstr) {
    print "Oracle Error:/n";
    print "--------------------------------------------------------/n";
    print "$ora_errstr/n";
  }

  # +-------------------------------------+
  # | SEND THIS OUTPUT TO THE MAIL SYSTEM |
  # +-------------------------------------+

  if ($email_who) {

    $AUTO_MESSAGE = "/n";
    $AUTO_MESSAGE .= "+-------------------------------------------------------+/n";
    $AUTO_MESSAGE .= "| The following message was automatically               |/n";
    $AUTO_MESSAGE .= "| genereated by the Sysmon System.                      |/n";
    $AUTO_MESSAGE .= "+-------------------------------------------------------+/n";
    $AUTO_MESSAGE .= "/n";

    @EMAIL_ARRAY = split(/ /, $email_who);

    foreach (@EMAIL_ARRAY) {

      $TO = $_."/@fore.com";
      $FROM_FULL = "/"Sysmon Admin/"";
      $FROM = "/"dba/"";
      $Subject = "Sysmon Mail Error";

      open (MAIL,"|/usr/lib/sendmail -f $FROM -F $FROM_FULL $TO");
      print MAIL "To: $TO/n";
      print MAIL "From: $FROM/n";
      print MAIL "Reply-To: $FROM/n";
      print MAIL "Subject: $Subject/n/n";

      print MAIL "$AUTO_MESSAGE";

      print MAIL "+-------------------------------------------------------+/n";
      print MAIL "| ******************* PROGRAM ERROR ******************* |/n";
      print MAIL "+-------------------------------------------------------+/n";
      print MAIL "/n";
      print MAIL "/n";
      print MAIL "Message:/n";
      print MAIL "--------------------------------------------------------/n";
      print MAIL "$message/n";
      print MAIL "/n";
      if ($sql_statement) {
        print MAIL "SQL:/n";
        print MAIL "$sql_statement/n";
        print MAIL "--------------------------------------------------------/n";
        print MAIL "/n";
      }

      if ($ora_errstr) {
        print MAIL "Oracle Error:/n";
        print MAIL "--------------------------------------------------------/n";
        print MAIL "$ora_errstr/n";
      }

      close MAIL;
    }
  }

  if ($page_who) {

    @PAGER_ARRAY = split(/ /, $page_who);

    foreach (@PAGER_ARRAY) {

      $TO = $_."/@fore.com";
      $FROM_FULL = "/"Sysmon Admin/"";
      $FROM = "/"dba/"";
      $Subject = "Sysmon Program Error";

      open (MAIL,"|/usr/lib/sendmail -f $FROM -F $FROM_FULL $TO");
      print MAIL "To: $TO/n";
      print MAIL "From: $FROM/n";
      print MAIL "Reply-To: $FROM/n";
      print MAIL "Subject: $Subject/n/n";

      print MAIL "$message/n";
      close MAIL;
    }
  }

}
lixing@lixing:~/fast_livo2/devel$ cd .. lixing@lixing:~/fast_livo2$ catkin_make install Base path: /home/lixing/fast_livo2 Source space: /home/lixing/fast_livo2/src Build space: /home/lixing/fast_livo2/build Devel space: /home/lixing/fast_livo2/devel Install space: /home/lixing/fast_livo2/install #### #### Running command: "make cmake_check_build_system" in "/home/lixing/fast_livo2/build" #### #### #### Running command: "make install -j8 -l8" in "/home/lixing/fast_livo2/build" #### [ 0%] Built target std_msgs_generate_messages_cpp [ 0%] Built target std_msgs_generate_messages_nodejs [ 0%] Built target std_msgs_generate_messages_lisp [ 0%] Built target std_msgs_generate_messages_eus [ 0%] Built target std_msgs_generate_messages_py [ 0%] Built target _livox_ros_driver2_generate_messages_check_deps_CustomMsg [ 20%] Built target vikit_common [ 20%] Built target _livox_ros_driver2_generate_messages_check_deps_CustomPoint [ 26%] Built target vio [ 30%] Built target imu_proc [ 33%] Built target laser_mapping [ 36%] Built target lio [ 39%] Built target pre [ 42%] Built target test_vk_common_patch_score [ 46%] Built target test_vk_common_camera [ 49%] Built target livox_ros_driver2_generate_messages_nodejs [ 52%] Built target livox_ros_driver2_generate_messages_lisp [ 55%] Built target livox_ros_driver2_generate_messages_cpp [ 58%] Built target test_vk_common_triangulation [ 65%] Built target vikit_ros [ 66%] Built target livox_ros_driver2_generate_messages_eus [ 71%] Built target livox_ros_driver2_generate_messages_py [ 71%] Built target livox_ros_driver2_generate_messages [ 96%] Built target livox_ros_driver2_node [100%] Built target fastlivo_mapping Install the project... -- Install configuration: "Release" -- Installing: /home/lixing/fast_livo2/install/_setup_util.py -- Installing: /home/lixing/fast_livo2/install/env.sh -- Installing: /home/lixing/fast_livo2/install/setup.bash -- Installing: /home/lixing/fast_livo2/install/local_setup.bash -- Installing: /home/lixing/fast_livo2/install/setup.sh -- Installing: /home/lixing/fast_livo2/install/local_setup.sh -- Installing: /home/lixing/fast_livo2/install/setup.zsh -- Installing: /home/lixing/fast_livo2/install/local_setup.zsh -- Installing: /home/lixing/fast_livo2/install/setup.fish -- Installing: /home/lixing/fast_livo2/install/local_setup.fish -- Installing: /home/lixing/fast_livo2/install/.rosinstall -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/msg/CustomPoint.msg -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/msg/CustomMsg.msg -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/cmake/livox_ros_driver2-msg-paths.cmake -- Installing: /home/lixing/fast_livo2/install/include/livox_ros_driver2 -- Installing: /home/lixing/fast_livo2/install/include/livox_ros_driver2/CustomMsg.h -- Installing: /home/lixing/fast_livo2/install/include/livox_ros_driver2/CustomPoint.h -- Installing: /home/lixing/fast_livo2/install/share/roseus/ros/livox_ros_driver2 -- Installing: /home/lixing/fast_livo2/install/share/roseus/ros/livox_ros_driver2/msg -- Installing: /home/lixing/fast_livo2/install/share/roseus/ros/livox_ros_driver2/msg/CustomMsg.l -- Installing: /home/lixing/fast_livo2/install/share/roseus/ros/livox_ros_driver2/msg/CustomPoint.l -- Installing: /home/lixing/fast_livo2/install/share/roseus/ros/livox_ros_driver2/manifest.l -- Installing: /home/lixing/fast_livo2/install/share/common-lisp/ros/livox_ros_driver2 -- Installing: /home/lixing/fast_livo2/install/share/common-lisp/ros/livox_ros_driver2/msg -- Installing: /home/lixing/fast_livo2/install/share/common-lisp/ros/livox_ros_driver2/msg/_package_CustomMsg.lisp -- Installing: /home/lixing/fast_livo2/install/share/common-lisp/ros/livox_ros_driver2/msg/CustomPoint.lisp -- Installing: /home/lixing/fast_livo2/install/share/common-lisp/ros/livox_ros_driver2/msg/_package_CustomPoint.lisp -- Installing: /home/lixing/fast_livo2/install/share/common-lisp/ros/livox_ros_driver2/msg/livox_ros_driver2-msg.asd -- Installing: /home/lixing/fast_livo2/install/share/common-lisp/ros/livox_ros_driver2/msg/_package.lisp -- Installing: /home/lixing/fast_livo2/install/share/common-lisp/ros/livox_ros_driver2/msg/CustomMsg.lisp -- Installing: /home/lixing/fast_livo2/install/share/gennodejs/ros/livox_ros_driver2 -- Installing: /home/lixing/fast_livo2/install/share/gennodejs/ros/livox_ros_driver2/msg -- Installing: /home/lixing/fast_livo2/install/share/gennodejs/ros/livox_ros_driver2/msg/CustomMsg.js -- Installing: /home/lixing/fast_livo2/install/share/gennodejs/ros/livox_ros_driver2/msg/CustomPoint.js -- Installing: /home/lixing/fast_livo2/install/share/gennodejs/ros/livox_ros_driver2/msg/_index.js -- Installing: /home/lixing/fast_livo2/install/share/gennodejs/ros/livox_ros_driver2/_index.js Listing '/home/lixing/fast_livo2/devel/lib/python3/dist-packages/livox_ros_driver2'... Compiling '/home/lixing/fast_livo2/devel/lib/python3/dist-packages/livox_ros_driver2/__init__.py'... Listing '/home/lixing/fast_livo2/devel/lib/python3/dist-packages/livox_ros_driver2/msg'... Compiling '/home/lixing/fast_livo2/devel/lib/python3/dist-packages/livox_ros_driver2/msg/_CustomMsg.py'... Compiling '/home/lixing/fast_livo2/devel/lib/python3/dist-packages/livox_ros_driver2/msg/_CustomPoint.py'... Compiling '/home/lixing/fast_livo2/devel/lib/python3/dist-packages/livox_ros_driver2/msg/__init__.py'... -- Installing: /home/lixing/fast_livo2/install/lib/python3/dist-packages/livox_ros_driver2 -- Installing: /home/lixing/fast_livo2/install/lib/python3/dist-packages/livox_ros_driver2/__init__.py -- Installing: /home/lixing/fast_livo2/install/lib/python3/dist-packages/livox_ros_driver2/msg -- Installing: /home/lixing/fast_livo2/install/lib/python3/dist-packages/livox_ros_driver2/msg/__init__.py -- Installing: /home/lixing/fast_livo2/install/lib/python3/dist-packages/livox_ros_driver2/msg/_CustomMsg.py -- Installing: /home/lixing/fast_livo2/install/lib/python3/dist-packages/livox_ros_driver2/msg/__pycache__ -- Installing: /home/lixing/fast_livo2/install/lib/python3/dist-packages/livox_ros_driver2/msg/__pycache__/__init__.cpython-38.pyc -- Installing: /home/lixing/fast_livo2/install/lib/python3/dist-packages/livox_ros_driver2/msg/__pycache__/_CustomMsg.cpython-38.pyc -- Installing: /home/lixing/fast_livo2/install/lib/python3/dist-packages/livox_ros_driver2/msg/__pycache__/_CustomPoint.cpython-38.pyc -- Installing: /home/lixing/fast_livo2/install/lib/python3/dist-packages/livox_ros_driver2/msg/_CustomPoint.py -- Installing: /home/lixing/fast_livo2/install/lib/python3/dist-packages/livox_ros_driver2/__pycache__ -- Installing: /home/lixing/fast_livo2/install/lib/python3/dist-packages/livox_ros_driver2/__pycache__/__init__.cpython-38.pyc -- Installing: /home/lixing/fast_livo2/install/lib/pkgconfig/livox_ros_driver2.pc -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/cmake/livox_ros_driver2-msg-extras.cmake -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/cmake/livox_ros_driver2Config.cmake -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/cmake/livox_ros_driver2Config-version.cmake -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/package.xml -- Installing: /home/lixing/fast_livo2/install/lib/livox_ros_driver2/livox_ros_driver2_node -- Set runtime path of "/home/lixing/fast_livo2/install/lib/livox_ros_driver2/livox_ros_driver2_node" to "" -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/launch_ROS1 -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/launch_ROS1/msg_mixed.launch -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/launch_ROS1/msg_HAP.launch -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/launch_ROS1/msg_MID360.launch -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/launch_ROS1/rviz_MID360.launch -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/launch_ROS1/rviz_mixed.launch -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/launch_ROS1/rviz_HAP.launch -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/config -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/config/HAP_config.json -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/config/display_point_cloud_ROS1.rviz -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/config/mixed_HAP_MID360_config.json -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/config/display_point_cloud_ROS2.rviz -- Installing: /home/lixing/fast_livo2/install/share/livox_ros_driver2/config/MID360_config.json -- Installing: /home/lixing/fast_livo2/install/lib/pkgconfig/vikit_common.pc -- Installing: /home/lixing/fast_livo2/install/share/vikit_common/cmake/vikit_commonConfig.cmake -- Installing: /home/lixing/fast_livo2/install/share/vikit_common/cmake/vikit_commonConfig-version.cmake -- Installing: /home/lixing/fast_livo2/install/share/vikit_common/package.xml + cd /home/lixing/fast_livo2/src/rpg_vikit/vikit_py + mkdir -p /home/lixing/fast_livo2/install/lib/python3/dist-packages + /usr/bin/env PYTHONPATH=/home/lixing/fast_livo2/install/lib/python3/dist-packages:/home/lixing/fast_livo2/build/lib/python3/dist-packages:/home/lixing/fast_livo2/devel/lib/python3/dist-packages:/opt/ros/noetic/lib/python3/dist-packages CATKIN_BINARY_DIR=/home/lixing/fast_livo2/build /usr/bin/python3 /home/lixing/fast_livo2/src/rpg_vikit/vikit_py/setup.py build --build-base /home/lixing/fast_livo2/build/rpg_vikit/vikit_py install --root=/ --install-layout=deb --prefix=/home/lixing/fast_livo2/install --install-scripts=/home/lixing/fast_livo2/install/bin running build running build_py creating /home/lixing/fast_livo2/build/rpg_vikit/vikit_py/lib creating /home/lixing/fast_livo2/build/rpg_vikit/vikit_py/lib/vikit_py copying src/vikit_py/depthmap_utils.py -> /home/lixing/fast_livo2/build/rpg_vikit/vikit_py/lib/vikit_py copying src/vikit_py/__init__.py -> /home/lixing/fast_livo2/build/rpg_vikit/vikit_py/lib/vikit_py copying src/vikit_py/math_utils.py -> /home/lixing/fast_livo2/build/rpg_vikit/vikit_py/lib/vikit_py copying src/vikit_py/transformations.py -> /home/lixing/fast_livo2/build/rpg_vikit/vikit_py/lib/vikit_py copying src/vikit_py/align_trajectory.py -> /home/lixing/fast_livo2/build/rpg_vikit/vikit_py/lib/vikit_py copying src/vikit_py/ros_node.py -> /home/lixing/fast_livo2/build/rpg_vikit/vikit_py/lib/vikit_py copying src/vikit_py/cpu_info.py -> /home/lixing/fast_livo2/build/rpg_vikit/vikit_py/lib/vikit_py running install running install_lib creating /home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py copying /home/lixing/fast_livo2/build/rpg_vikit/vikit_py/lib/vikit_py/depthmap_utils.py -> /home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py copying /home/lixing/fast_livo2/build/rpg_vikit/vikit_py/lib/vikit_py/__init__.py -> /home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py copying /home/lixing/fast_livo2/build/rpg_vikit/vikit_py/lib/vikit_py/math_utils.py -> /home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py copying /home/lixing/fast_livo2/build/rpg_vikit/vikit_py/lib/vikit_py/transformations.py -> /home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py copying /home/lixing/fast_livo2/build/rpg_vikit/vikit_py/lib/vikit_py/align_trajectory.py -> /home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py copying /home/lixing/fast_livo2/build/rpg_vikit/vikit_py/lib/vikit_py/ros_node.py -> /home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py copying /home/lixing/fast_livo2/build/rpg_vikit/vikit_py/lib/vikit_py/cpu_info.py -> /home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py byte-compiling /home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py/depthmap_utils.py to depthmap_utils.cpython-38.pyc byte-compiling /home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py/__init__.py to __init__.cpython-38.pyc byte-compiling /home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py/math_utils.py to math_utils.cpython-38.pyc byte-compiling /home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py/transformations.py to transformations.cpython-38.pyc byte-compiling /home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py/align_trajectory.py to align_trajectory.cpython-38.pyc byte-compiling /home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py/ros_node.py to ros_node.cpython-38.pyc byte-compiling /home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py/cpu_info.py to cpu_info.cpython-38.pyc running install_egg_info Writing /home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py-0.0.0.egg-info /usr/lib/python3.8/distutils/dist.py:274: UserWarning: Unknown distribution option: 'install_requires' warnings.warn(msg) File "home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py/depthmap_utils.py", line 15 print 'Could not open file ' + depthmap_full_file_path + ' for reading binary data.' ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Could not open file ' + depthmap_full_file_path + ' for reading binary data.')? -- Installing: /home/lixing/fast_livo2/install/lib/pkgconfig/vikit_py.pc -- Installing: /home/lixing/fast_livo2/install/share/vikit_py/cmake/vikit_pyConfig.cmake -- Installing: /home/lixing/fast_livo2/install/share/vikit_py/cmake/vikit_pyConfig-version.cmake -- Installing: /home/lixing/fast_livo2/install/share/vikit_py/package.xml -- Installing: /home/lixing/fast_livo2/install/lib/pkgconfig/vikit_ros.pc -- Installing: /home/lixing/fast_livo2/install/share/vikit_ros/cmake/vikit_rosConfig.cmake -- Installing: /home/lixing/fast_livo2/install/share/vikit_ros/cmake/vikit_rosConfig-version.cmake -- Installing: /home/lixing/fast_livo2/install/share/vikit_ros/package.xml -- Installing: /home/lixing/fast_livo2/install/lib/pkgconfig/fast_livo.pc -- Installing: /home/lixing/fast_livo2/install/share/fast_livo/cmake/fast_livoConfig.cmake -- Installing: /home/lixing/fast_livo2/install/share/fast_livo/cmake/fast_livoConfig-version.cmake -- Installing: /home/lixing/fast_livo2/install/share/fast_livo/package.xml
最新发布
07-22
<think>好的,用户现在遇到了在安装ROS包时出现的错误,具体是关于`depthmap_utils.py`文件中print语句的语法错误。我需要仔细分析这个问题,并给出解决方案。 首先,用户执行了`catkin_make install`命令,编译和安装整个工作空间。安装过程中,系统提示了一个语法错误:在`depthmap_utils.py`的第15行,print语句缺少括号。这说明代码中存在Python 2的print语法,而用户的环境可能使用的是Python 3,因为Python 3的print需要括号。 接下来,我需要确定问题的根源。用户可能是在Python 3环境下运行了原本为Python 2编写的代码,导致语法错误。错误信息中的`print 'Could not open file ...'`是Python 2的写法,正确的Python 3写法应该是`print('Could not open file ...')`。因此,需要修改源代码中的print语句。 然后,我需要考虑如何指导用户修改代码。用户可能对Python版本差异不太熟悉,所以需要明确说明问题所在,并提供具体的修改步骤。此外,用户可能还关心如何避免类似的错误,以及如何验证修改是否有效。 另外,用户之前的问题涉及ROS的启动文件路径问题,现在这个问题可能属于同一项目中的不同模块。需要确保用户在修改代码后重新编译安装,并检查其他可能存在的Python 2兼容性问题。 还要注意用户的工作环境,比如他们使用的是ROS Noetic,这通常支持Python 2和3,但某些包可能需要特定版本。需要确认用户使用的Python版本是否正确,以及是否需要调整ROS的Python环境配置。 最后,确保提供的解决方案清晰、具体,并且涵盖可能的相关问题,比如如何检查Python版本、如何修改其他类似的print语句,以及如何验证安装是否成功。</think>根据编译日志,错误发生在`vikit_py`模块的`depthmap_utils.py`文件中,具体提示为`print`语句缺少括号。这是由于代码中使用了Python 2的`print`语法(无括号),而当前环境使用的是Python 3(需要括号)。以下是解决方案: --- ### **问题定位** 错误代码片段: ```python print 'Could not open file ' + depthmap_full_file_path + ' for reading binary data.' ``` Python 3要求`print`语句必须使用括号: ```python print('Could not open file ' + depthmap_full_file_path + ' for reading binary data.') ``` --- ### **解决方案** #### 1. **修改`depthmap_utils.py`文件** - 打开文件: ```bash nano /home/lixing/fast_livo2/src/rpg_vikit/vikit_py/src/vikit_py/depthmap_utils.py ``` - 找到第15行,将: ```python print 'Could not open file ' + depthmap_full_file_path + ' for reading binary data.' ``` 修改为: ```python print('Could not open file ' + depthmap_full_file_path + ' for reading binary data.') ``` #### 2. **重新编译并安装** - 清理并重新编译: ```bash cd ~/fast_livo2 catkin_make clean catkin_make install ``` #### 3. **验证Python版本兼容性** - 确认当前Python版本: ```bash python3 --version ``` 如果版本为3.x,则需要确保所有Python代码兼容Python 3。 #### 4. **检查其他Python文件** - 查找项目中其他可能存在的Python 2语法问题: ```bash find /home/lixing/fast_livo2/src -name "*.py" -exec grep -l "print " {} \; ``` - 对输出的文件逐个检查`print`语句是否缺少括号,并修复。 --- ### **附加建议** 1. **使用`2to3`工具自动转换** 对于大规模代码兼容性问题,可使用Python自带的`2to3`工具: ```bash 2to3 -w /home/lixing/fast_livo2/src/rpg_vikit/vikit_py/src/vikit_py/ ``` 2. **指定Python解释器版本** 在ROS的`CMakeLists.txt`中强制使用Python 3: ```cmake set(PYTHON_VERSION 3) ``` 3. **验证安装结果** 安装完成后,检查`depthmap_utils.py`是否已正确编译: ```bash cat /home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py/depthmap_utils.py ``` --- ### **验证步骤** 1. 确保所有修改已保存。 2. 重新编译并安装: ```bash cd ~/fast_livo2 catkin_make install ``` 3. 检查是否生成正确的`.pyc`文件: ```bash ls /home/lixing/fast_livo2/install/lib/python3/dist-packages/vikit_py/__pycache__/depthmap_utils.cpython-38.pyc ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值