Python 3 and Vagrant without Virtualenv - python-3.x

I want to set up a Ubuntu VM with Python 3. All the resources I've seen so far want me to use virtualenv but I don't see the point since I only want one Python (I don't care about 2.7 in other words).
Is there a way to do this where I can just ssh into the VM and my environment is all set up for me?

There are no Ubuntu releases that default to Python 3. Maybe in the future, but as of right now, you will have to workaround the fact that Ubuntu ships with Python 2 as the default, Python 3 is available.
So pick a release of Ubuntu that you like, and then:
Upgrade the system (sudo apt update; sudo apt upgrade -y)
Install the build toolchain (sudo apt install build-essential -y)
Install Python3 (sudo apt install python3 python3-dev -y)
Switch your user to Python3 as the default; I would recommend using pyenv for this.
Once you do this, then for your user Python will default to Python 3, but for other system utilities, Python 2 will still be available.
It might just be easier to use the default Python docker image since its allows you to easily switch versions (it is based on debian).

Related

Is it possible to install npm without python 2?

Context: I would like to install clasp via npm for Google Apps Script development. I'm on Ubuntu 20.04.
apt-get -s install npm shows my machine trying to install python 2 - which I don't have and don't want.
Is it possible to install npm (and therefore clasp) without having to accept python 2 and getting mired in python version problems on my machine?
No, I'm quite sure npm needs python 2. I have both python 2 & 3 on my ubuntu 20.04, and I've never had any problems caused by using both.
Also, you should probably use apt install instead of apt-get (not a significant change just, more modern and faster). Here is a link on the differences: https://itsfoss.com/apt-vs-apt-get-difference/

why does supervisor 3.3 still setup python2.7

While setting up supervisor on an Ubuntu machine via apt-get install supervisor, I noticed it setting up python2.7 as part of the installation.
I have 2 questions -
Why supervisor 3.3.1 which is relatively very new still using
python2.7? The old version was not present on my system till apt-get
installed it as a sub-dependency.
What can I do to have supervisor depend on python3.x?
Supervisor currently does not support Python 3. See the platform requirements:
Supervisor is known to work with Python 2.4 or later but will not work under any version of Python 3.

Python 3.6 in tensorflow gpu docker images

How can I have python3.6 in tensorflow docker images.
All the images I tried (latest, nighty) are using python3.5 and I don't want to modify all my scripts.
The Tensorflow images are based on Ubuntu 16.04, as you can see from the Dockerfile. This release ships with Python 3.5 as standard.
So you'll have to re-build the image, and the Dockerfile will need editing, even though you need to do the actual build with the parameterized_docker_build.sh script.
This answer on ask Ubuntu covers how to get Python 3.6 on Ubuntu 16.04
The simplest way would probably be just to change the From line in the Dockerfile to FROM ubuntu:16.10, and python to python3.6 in the initial apt-get install line
Of course, this may break some other Ubuntu version-specific thing, so an alternative would be to keep Ubuntu 16.04 and install one of the alternative ppa's also listed in the linked answer:
RUN add-apt-repository ppa:deadsnakes/ppa &&
apt-get update &&
apt-get install -y python3.6
Note that you'll need this after the initial apt-get install, because that installs software-properties-common, which you need to add the ppa.
Note also, as in the comments to the linked answer, that you will need to symlink to Python 3.6.
Finally, note that I haven't tried any of this. The may be gotchas, and you may need to make another change to ensure that the correct version of Python is used by the running container.
You can use stable images which are supplied by third parties, like ufoym/deepo.
One that fits TensorFlow, python3.6 and cuda10 can be found here or you can pull it directly using the command docker pull ufoym/deepo:py36-cu100
I use their images all the time, never had problems
With this anwer, I just wanted to specify how I solved this problem (the previous answer of SiHa helped me a lot but I had to add a few steps so that it worked completly).
Context:
I'm using a package (segmentation model for unet++) that requires tensorflow==1.4.0 and keras==2.2.2.
I tried to use the docker image for tensorflow 1.4.0, however, the default version of python of this image is 3.5 which is not compatible with my package.
I managed to install python3.6 on the docker images thanks to the following files:
My Dockerfile contains the following lines:
Dockerfile:
FROM tensorflow/tensorflow:1.4.0-gpu-py3
RUN mkdir /AI_PLATFORM
WORKDIR /AI_PLATFORM
COPY ./install.sh ./install.sh
COPY ./requirements.txt ./requirements.txt
COPY ./computer_vision ./computer_vision
COPY ./config.ini ./config.ini
RUN bash install.sh
Install.sh:
#!/urs/bin/env bash
pip install --upgrade pip
apt-get update
apt-get install -y python3-pip
add-apt-repository ppa:deadsnakes/ppa &&
apt-get update &&
apt-get install python3.6 --assume-yes
apt-get install libpython3.6
python3.6 -m pip install --upgrade pip
python3.6 -m pip install -r requirements.txt
Three things are important:
use python3.6 -m pip instead of pip, else the packages are installed on python 3.5 default version of Ubuntu 16.04
use docker run python3.6 <command> to run your containers with python==3.6
in the requirements.txt file, I had to specify the following things:
h5py==2.10.0
tensorflow-gpu==1.4.1
keras==2.2.2
keras-applications==1.0.4
keras-preprocessing==1.0.2
I hope that this answer will be useful
Maybe the image I created will help you. It is based on the cuda-10.0-devel image and has tensorflow 2.0a-gpu installed.
You can use it as base image for your own implementation. The image itself doesn't do anything. I put the image on dockerhub https://cloud.docker.com/repository/docker/patientzero/tensorflow2.0a-gpu-py3.6
The github repo is located here: https://github.com/patientzero/tensorflow2.0-python3.6-Docker
Pulling it won't do much, but for completeness:
$ docker pull patientzero/tensorflow2.0-gpu-py3.6
edit: changed to general tensorflow 2.0x image.
Also as mentioned here, the official image for the beta 2.0 release now comes with python 3.6 support

Ansible: ufw is not a legal parameter in an ansible task or handler

Trying to run an ansible installation on ubuntu 14.04
ansible-playbook -i hosts ruby-webapp.yml -t swap,ruby,deploy,mysql,nginx,ufw,import_data
I get
ERROR: ufw is not a legal parameter in an Ansible task or handler
and I can't go forward with the rest of the installation.
ufw was was added as a system module to Ansible 1.6 (see http://docs.ansible.com/ufw_module.html).
You are probably running an older version of Ansible on your control node (i.e., the machine where you are invoking the ansible-playbook command). Check your version with:
ansible --version
Upgrading depends on how you installed Ansible originally, but if you installed it to your system as root using pip, you can probably use:
sudo pip install -U ansible
(The -U means "update")
Edit: Just realized that you might be running Ubuntu 14.04 as your control node so I checked to see what version you get when you install Ansible with apt-get. As of this writing, it installs version 1.5.4, so if that's how you installed it, you definitely have the wrong version. You probably want to uninstall the OS package version and use one of the recommended installation techniques: http://docs.ansible.com/intro_installation.html#running-from-source
Something like:
sudo apt-get remove ansible
sudo easy_install pip
sudo pip install ansible
If you are missing easy_install, you may install it with:
sudo apt-get install python-setuptools

Step by step: Installing Python 3.3, Lighttpd & Pymongo on Ubuntu 12.04

I'm currently migrating to new computer and I need to reinstall the software I am using which are:
Python 3.3,
Lighttpd (newest version),
Pymongo (newest version),
Ubuntu 12.04 Desktop (The System I'm using)
I started to install Python 3.3 by downloading it from the its official website (in tar.bz2 file) and by following this tutorial. Afterwards I installed Lighttpd and changed the lighttpd.conf for Python by following this tutorial, too.
I tried several paths for my cgi.assign, none of them worked. Especially /opt/python3.3/bin/python3.3 should be working, but it shows 500 - internal Server error all the time with a "hello world" test script.
Now regardless to this problem I have no clue on installing Pymongo. If I try to intall pip OR easy_install python3.3 I have to manually download it and execute the setup.py with my python3.3 executable, right? Because this always fails with an error:
`Error missing zlib on a bundle called distribute-0.7.3 (is this even the right tool I need, because it seems to be a legacy wrapper !?) or unknown url type: https for pymongo2.6.2 itself.`
I'm getting crazy with this setup. Why is this so difficult to handle? Other programs are just a few clicks to install even on a system like Ubuntu, but these particular development tools seem to be really difficult to install.If anybody has an idea on how to install all three together or has information on a better solution please help me out.
The system is used to program Python scripts in Eclipse and trying them out directly on the system (lighttpd). The database used is MongoDB. Python and MongoDB are communicating over the Pymongo driver. I am planning to use the system on a Server distribution on release and it has to be nicely scalable on a high amount of excecutions.
Thanks for your time,
It's easiest to use the Ubuntu repositories:
sudo apt-get update
sudo apt-get install python3 python3-pip lightppd python-pymongo
Or if that only installs the python2.x pymongo, use pip, which you've just installed:
sudo pip-3.3 install pymongo
Or better yet, use a virtualenv with the help of virtualenvwrapper (docs)
sudo pip install virtualenvwrapper
... # follow instructions for installing virtualenvwrapper
mkvirtualenv --python=/usr/bin/python3 -i pymongo mongoppd
workon mongoppd
... which will segregate the environment I've called 'mongoppd' from the rest of your system so you can't cause any trouble. Then you don't need sudo to pip-3.3 install things, just workon mongoppd then pip-3.3 install [...]. Or after the -i flag when you create the virtualenv to get it installed straight away.
In general, on Ubuntu, you should hardly ever have to install something manually. Your first attempt should be using sudo apt-get install (use tab-complete to see what's available or just google "ubuntu 12.04 packages [...]" and you'll find the list of packages). Then for python use pip install or pip-3.3 install as appropriate. You'll only need to run python setup.py install if you need to install a development version of a package or something obscure that's not on pip. I don't think there's a good reason to ever use easy_install these days.

Resources