Tag Archives: python

How to update python packages to the latest version

Recently I wanted to update my python packages and really wasn’t a way to easily update them until I ran into Stack Overflow question on how to do it. Which it worked neatly.

Here are the steps on how to do it in your python environment

pip list --outdated --format=freeze #list outdated packages
pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U

If you have a specific python version, you can invoke it this way

pip2.7 list --outdated --format=freeze #list outdated packages
pip2.7 freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo -H pip2.7 install -U

Sources
https://stackoverflow.com/questions/2720014/upgrading-all-packages-with-pip

Python Mediacom Data Usage Prediction (mdup) via SMS

After years of monitoring my data usage and going over, I decided to make a dashboard (yes, like your car dashboard) for my ISP data usage.

I decided to publish this piece of code with the hopes that would help other people setting something up, where they could be notified via text message/SMS on their current data usage and predict what their usage will be by the end of the [billing] cycle.

Here is the repo -> https://github.com/blacknred0/mdup and the name of the project is “Mediacom Data Usage Prediction (mdup) via SMS”.

Python – Install pip and virtualenv and distribute without sudo access

Recently I started to so some dev on python and noticed that on the server that I was going to do the work I don’t have sudo access.  In the past, this has not been an issue, but in this case getting sudo access is almost impossible and not doable.  So my only option is being able to run pip (to install python packages) as an user.

After painfully researching on how to successfully do this, I was able to make it work.  I hope that this helps others in the future. Good luck!

  1. Make sure that you have python installed
    which python
  2. Download latest version of virtual environment (virtualenv)
    wget https://pypi.python.org/packages/d4/0c/9840c08189e030873387a73b90ada981885010dd9aea134d6de30cd24cb8/virtualenv-15.1.0.tar.gz#md5=44e19f4134906fe2d75124427dc9b716
    
  3. Unpack source tarball
    tar -xzf virtualenv-15.1.0.tar.gz
  4. Create your package environment
    python virtualenv-15.1.0/virtualenv.py py-packages
  5. Delete the virtual environment folder
    rm -rfv virtualenv-15.1.0
  6. Install virtualenv into your environment.  You can use the package that you downloaded or using pip.
    py-packages/bin/pip install virtualenv-15.1.0.tar.gz

    or

    py-packages/bin/pip install virtualenv
  7. If you want to clone environments you can do the following
    py-packages/bin/virtualenv py-clone1

Sources:
http://stackoverflow.com/questions/4324558/whats-the-proper-way-to-install-pip-virtualenv-and-distribute-for-python
https://pypi.python.org/pypi/virtualenv
https://packaging.python.org/installing/

How to install a new version of python in RHEL 6

So, if you have RHEL 6, you might be stuck with Python 2.6.  But, not really.  Even though you might not be able to install a new version of python using yum, you can still download a new version of python and install it in your environment.  Now, you can install it and replace the current version or you can install another version and have two python in your system.

  1. Install GCC by typing
    sudo yum install gcc
  2. Go to
    cd /usr/src/
  3. Now, let’s download a release from python.org. In this example we will be using Python 3.5.0.

    sudo wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz sudo tar xf Python-3.5.0.tar.xz sudo cd Python-3.5.0
  4. Let’s compile
    sudo ./configure
  5. Let’s build the package
    sudo make
  6. Now, to install it you have two options.  You can either overwrite the python executable or you can install as concurrent instance.
    1. If you want to overwrite the OS python executable
       sudo make install
    2. If you want to install concurrent (not overwritting the OS executable)
       sudo make altinstall
  7. Now let’s link it so others could use it
     sudo ln -s /usr/local/bin/python3.5 /usr/bin/python3.5
  8. Now test it by invoking the following command
    python3.5 -V

    You should have the following result

    "Python 3.5.0"
  9. If you get that result let’s continue, otherwise look back and see what step you missed.
  10. Now that you have python 3.5 install along with 2.7, you might want to install pip to handle package installations.
  11. In order to do that, let’s first download pip.
    cd ~/Downloads
    wget https://bootstrap.pypa.io/get-pip.py
  12. Now, let’s install it
     sudo python3.5 get-pip.py

    If setuptools is not installed, get-pip.py will automatically install setuptools.

  13. To check pip if installed successfully
     pip3.5 -V

    You should have the following result

     "pip 7.1.2 from /usr/local/lib/python3.5/site-packages (python 3.5)"
  14. If you want others to use pip with sudo command, you probably want to do this
  15. sudo ln -s /usr/local/bin/pip3.5 /usr/bin/pip3.5
  16. And there you go!  Now you have two python versions and two pip versions running concurrently on your OS.

Sources

https://www.python.org/

https://pip.pypa.io/en/stable/installing/

http://stackoverflow.com/questions/8087184/installing-python3-on-rhel

http://stackoverflow.com/questions/6587507/how-to-install-pip-with-python-3