I have the following code...
FROM python:latest
ENV VIRTUAL_ENV "/venv"
RUN python -m venv $VIRTUAL_ENV
ENV PATH "$VIRTUAL_ENV/bin:$PATH"
# Python commands run inside the virtual environment
RUN /venv/bin/python3 -m pip install --upgrade pip
RUN /venv/bin/pip3 install tensorflow
But when I run I get...
ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow
I tried using the tensorflow image like...
FROM tensorflow/tensorflow:latest
ENV VIRTUAL_ENV "/venv"
RUN python -m venv $VIRTUAL_ENV
ENV PATH "$VIRTUAL_ENV/bin:$PATH"
# Python commands run inside the virtual environment
RUN /venv/bin/python3 -m pip install --upgrade pip
but then I get...
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt-get install python3-venv
So I change to
FROM tensorflow/tensorflow:latest
RUN apt-get install python3-venv -y
ENV VIRTUAL_ENV "/venv"
RUN python -m venv $VIRTUAL_ENV
ENV PATH "$VIRTUAL_ENV/bin:$PATH"
# Python commands run inside the virtual environment
RUN /venv/bin/python3 -m pip install --upgrade pip
But I get...
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/universe/p/python3.6/python3.6-venv_3.6.9-1~18.04ubuntu1.1_amd64.deb 404 Not Found [IP: 91.189.88.152 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
How do I handle this?
Per #drum comment this works...
FROM tensorflow/tensorflow:latest
RUN apt-get update && apt-get upgrade -y
RUN apt-get install python3-venv -y
ENV VIRTUAL_ENV "/venv"
RUN python -m venv $VIRTUAL_ENV
ENV PATH "$VIRTUAL_ENV/bin:$PATH"
# Python commands run inside the virtual environment
RUN /venv/bin/python3 -m pip install --upgrade pip
Related
enter image description hereI am try to install pip libraries in ec2-instances virtual environment using user data.
But while I am trying that I will create at instance level but not at virtual environment level.
What I need exactly is will I am creating ec2-instance on configuration level I want to define that to create pip libraries at virtual environment level.
#!/usr/bin/env bash
sudo yum update
sudo yum install python3 pip3 -y
sudo pip3 install --upgrade pip
pip install --upgrade pip
python3 -m venv /home/ec2-user/vertual-Environment
pip install django
pip install djangorestframework
pip install pillow
You have to source your python env envrionment.
Example (I have verified now the code on Amazon Linux 2):
#!/usr/bin/env bash
sudo yum update -y
sudo yum install python3 python3-pip -y
sudo pip3 install --upgrade pip
pip install --upgrade pip
python3 -m venv /home/ec2-user/vertual-Environment
# source your new python env
source /home/ec2-user/vertual-Environment/bin/activate
pip install django
pip install djangorestframework
pip install pillow
Using user data, your should install your dependencies this way :
python3 -m venv /home/ec2-user/vertual-Environment
/home/ec2-user/vertual-Environment/bin/pip install django
/home/ec2-user/vertual-Environment/bin/pip install djangorestframework
/home/ec2-user/vertual-Environment/bin/pip install pillow
When using userdata, your script are executed independently, regardless of what have been done in previous executions.
I want to create a venv having python3.8 as python3
On Ubuntu 18.04
I did:
> sudo apt install python3.8 python3.8-venv
Now, when I try:
> python3.8 -m venv env
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt-get install python3-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: ['/home/pushp/vizio-backend/env/bin/python3.8', '-Im', 'ensurepip', '--upgrade', '--default-pip']
My application depends on python3.8. What am I missing here?
Resolved, what I did? :
apt install python3.8 python3.8-venv python3-venv
Dont know how but installing both the venv packages python3.8-venv python3-venv resolved it from me. Now when I do:
python3.8 -m venv env
source env/bin/activate
python3 --version
> Python 3.8.0
first:
sudo pip3 install virtualenv
then cd to the directory where you want your virtual environment to be:
virtualenv "name of env" for ex: sudo virtualenv myProject-env
then to activate:
sudo source myProject-env/bin/activate
to make sure that it is work:
sudo which python
Installing python3-distutils also works around the problem.
You might miss the virtual environment installation in your machine.
You can install virtualenv using the following command,
sudo apt-get install python3.8-venv python3-venv
or
python3 -m pip install virtualenv
Referring this document from digitalOcean i got the same error but here in this linein this image change python3.6 to python3.8 then it will work fine.
change python3.6 -m venv my_env to python3.8 -m venv my_env
I am trying to enable virtualenv and install few pip packages. The below code doesn't enable the virtualenv. What I wanna do is Install python, pip, enable virtualenv, install boto3, seaborn, and sagemaker.
#!/bin/bash
yum update -y
sudo yum install python3 -y
curl -O https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py --user
pip3 install virtualenv
virtualenv venv
source venv/bin/activate
sudo pip3 install boto3
sudo pip3 install sagemaker
sudo pip3 install seaborn
I am passing the above code through userdata while creating an EC2 instance.
While running
$ sudo docker build -t myproj:tag .
I am hit with the message
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
and given recent occasional subtleties manifesting themselves with the error:
"/usr/bin/pip" "from pip import main" "ImportError: cannot import .."
I'd rather yield and indeed upgrade.
And so I add the pip upgrade command in the DockerFile, after the venv is built, since the pip that matters is the one inside the venv (am I getting this right?). So my Dockerfile now has this:
...
RUN python -m venv venv
RUN pip install --upgrade pip
...
But doing so does not avoid the "You are using pip 10.x" message. What am I missing?
Update
Though a promising suggestion, neither
RUN source venv/bin/activate
RUN pip install --upgrade pip
nor
RUN source venv/bin/activate
RUN python -m pip install --upgrade pip
eliminate the "You are using pip version 10.0.1, ..." message.
The single easiest answer to this is to just not bother with a virtual environment in a Docker image. A virtual environment gives you an isolated filesystem space with a private set of Python packages that don't conflict with the system install, but so does a Docker image. You can just use the system pip in a Docker image and it will be fine.
FROM python:3.7
RUN pip install --upgrade pip
WORKDIR /usr/src/app
COPY . .
RUN pip install .
CMD ["myscript"]
If you really want a virtual environment, you either need to specifically run the wrapper scripts from the virtual environment's path
RUN python -m venv venv
RUN venv/bin/pip install --upgrade pip
or run the virtual environment "activate" script on every RUN command; the environment variables it sets won't carry over from one step to another. (Each RUN command in effect does its own docker run; docker commit sequence under the hood and will launch a new shell in a new container; the Dockerfile reference describes this a little bit.)
RUN python -m venv venv
RUN . venv/bin/activate \
&& pip install --upgrade pip
COPY . .
RUN . venv/bin/activate \
&& pip install .
CMD ["venv/bin/myscript"]
Trying to activate the virtual environment in its own RUN instruction does nothing beyond generate a no-op layer.
# This step does nothing
RUN . venv/bin/activate
# And therefore this upgrades the system pip
RUN pip install --upgrade pip
Before you can use your virtual environment venvyou need to activate it with
On Windows:
venv\Scripts\activate.bat
On Unix or MacOS, run:
source venv/bin/activate
Please note that venv is the name of your environment. You created this environment with RUN python -m venv venv. I strongly recommend to use a other name.
Then you can upgrade with python -m pip install --upgrade pip
After you create a virtual environment in a Docker container through
RUN python -m venv venv
then run either
RUN venv/bin/pip install --upgrade pip
or
RUN venv/bin/python -m pip install --upgrade pip
but neither
RUN pip install --upgrade pip
nor
RUN python -m pip install --upgrade pip
I have python virtualenv and trying to install nodeenv it throws
"no python virtualenv is available"
inside my activated python virtual env with . bin/activate
I run the following commands
pip install nodeenv
nodeenv -p
And it throws the error... I'm currently trying to install less with django-compressor
This also happened to me, it's because nodeenv is not installed in your virtual environment. The following solved it for me:
sudo pip uninstall nodeenv
# Source your virtual environment.
source /path/to/virtualenv
pip install nodeenv
nodeenv -p
This happened to me on Mac OSX Yosemite.
I had installed nodeenv as a user. The solution was to install it as root:
pip uninstall nodeenv
sudo pip install nodeenv
# Source the virtual environment or use workon for virtualenvwrapper
workon <virtualenv name>
nodeenv -p