Monday 5 December 2016

Installing Python on Linux without disrupting existing one

Python is important package that comes installed on Linux systems. Corrupting the pre-installed version makes many of the packages non-usable. I could not yum after the pre-installed version of Python was corrupt.

Here is how you can install a version of Python on Linux operating system, keeping the pre-installed one safe. Here, we use CentOS 6.4 version, which is a pretty old release.

Issues solved by this document

pip is an important module you need while working on Python. Following are the errors I have faced while trying to install pip module and this document helps you in solving them too:
  • zipimport.ZipImportError: can't decompress data; zlib not available

    [root@localhost tmp]# python2.7 get-pip.py 
    Traceback (most recent call last):
      File "get-pip.py", line 20061, in 
        main()
      File "get-pip.py", line 194, in main
        bootstrap(tmpdir=tmpdir)
      File "get-pip.py", line 82, in bootstrap
        import pip
    zipimport.ZipImportError: can't decompress 
    data; zlib not available
    

  • There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available.

    [root@localhost tmp]# python2.7 get-pip.py 
    pip is configured with locations that require TLS/SSL, 
    however the ssl module in Python is not available.
    Collecting pip
      Could not fetch URL https://pypi.python.org/simple/p
    ip/: There was a problem confirming the ssl certificat
    e: Can't connect to HTTPS URL because the SSL module i
    s not available. - skipping
      Could not find a version that satisfies the requirem
    ent pip (from versions: )
    No matching distribution found for pip
    [root@localhost tmp]#
    

Verify the current version

You may use python --version command on the terminal to find the current version.

Installing a different version

  1. You may download a version you would need to install from Python Download. By default, Python comes as tarball for Linux.
  2. Once you have the tarball downloaded, copy it to a location where we extract and do the installation. Here, I copied the 2.7.12 version to /tmp. Use the version which is available for your platform and remember to use the commands accordingly.
  3. Extract tarball and change directory to the extracted folder.
    tar xvf Python-2.7.12.tar.xz
    cd Python-2.7.12
  4. Install required Linux packages. gcc is a utility for compiling and installing Python from source, zlib-devel and openssl-devel are required to avoid errors while installing pip module at a later stage. You would need to be root or a sudoer to install these packages:
    yum install gcc
    yum install zlib-devel
    yum install openssl-devel
  5. Run configure with option to export shared libraries. This is necessary if you would need to use pyinstaller module.
    ./configure --enable-shared
  6. Generate the build:
    make
  7. Install Python without replacing the existing version. Using altinstall option will help you to use the new installation with version suffix during execution. e.g. python2.7 --version:
    make altinstall
  8. Make a link to Python library path:
  • On 32 bit OS
    ln -s /usr/local/lib/libpython2.7.so.1.0 /usr/lib/libpython2.7.so.1.0
  • On 64 bit OS
     ln -s /usr/local/lib/libpython2.7.so.1.0 /usr/lib64/libpython2.7.so.1.0

 Installing pip module

Here is how you may get pip for the Python version you have just installed:
  1. Running get-pip.py is a better way to install pip. get-pip.py file is available at pip module listing.
  2. Run get-pip.py with the version of Python you have installed. For example:
    python2.7 get-pip.py
    This installs a pip utility which you can use with suffix. e.g. pip2.7 install pyinstaller 

Thursday 11 February 2016

Error: Failed to deploy OVF package: File ds:///*_deviceImage-0.iso was not found



This killer error would be enough to eat your productive time. Going through the forums does help you to fix this but the following are to be noted:


  1. OVA files are tar archive files with a .vmdk, .mf and .ovf files inside it.
  2. The files inside the OVA archives should be in specific order.
Here is what I had tried with no success:
  1. Unzipping the content, editing the respective files, zipping it again in .zip format and renaming to .ova. Used winrar tool for this. This may throw error "header not found".
  2. Using 7zip to extract the files, edit the required files and drag-drop updated files to 7zip. Just because 7zip utility changes the order of files in the archive, it gave error ".ovf file not found in the beginning of archive."
Solution:

Following steps are executed on a Linux machine. You may use tools such as cygwin to perform them on Windows.
  1. Rename the .ova file to .tar: mv myovafile.ova myovafile.tar
  2. List the .tar file to note down the order of its contents: tar -tf myovafile.tar
  3. Extract the tar archive: tar -xvf myovafile.tar
  4. Edit the .ovf file using text editor to have vmware.cdrom.remotepassthrough as rasd:ResourceSubType content for the rasd:ElementName with CD-ROM DVD value. You may refer VMware KB document.
  5. Calculate SHA1 for the .ovf file: sha1sum myovafile.ovf
  6. Update the SHA1 value to the .mf file using a text editor.
  7. Create tar file with the updated files. Pass files in the order they was displayed when step 2 was performed: tar -cvf mynewova.tar {fileslist_separated_by_space}
  8. Rename the file to have OVA extension: mv mynewova.tar mynewova.ova