Cannot Install into Virtual Environment - python

I have a virtual environment I have created on an Ubuntu virtal machine I am hosting on a windows PC. I intend to replicate my virtual machine in my virtal environment on the virtual machine. However, when trying to install modules to the VE I get a messgae saying that they are already installed - they're not installed in the VE but are on the VM. I thought when set active the VE would have no context of the VM which hosts it?
I have downloaded virtualenvironment sudo pip install virtualenv and then created a virtual environment sudo virtualenv virtual_environment. I then set the virtual environment to active source virtual_environment/bin/activate
When I try and do an apt-get install I get the message 0 upgraded, 0 newly installed, 0 to remove and 202 not upgraded despite the fact I have no modules whatsoever on the VE.
What am I doing wrong?
Thanks!

I think you're getting a bit confused about what virtualenv does. It is only for isolating Python files and libraries (those you install with pip install). It does nothing for your operating system files (those you install with apt-get).
If you want to create a re-usable container of operating system files (with apt-get) then look instead at something like Docker.

Related

Virtualenv seems to be active but really don't on MAC

I have a virtualenv called env on my directory...After activating:
source env/bin/activate
I see that it is activated...(env)
I have installed some libraries on the virtual env, and i can see that they ares installed on their folders, but calling...
pip list
The libraries that Appears on the list are not the libraries installed on the env.
Also calling a python file to execute, dontn run.
Therefore calling for checking the python version, don't match with the env python version.
I have tried to reinstall python and pip, but nothing happens
I work on a 2 macOS machines and I use iCloud for sharing my projects. I created the env on one macOS machine but the same env didn't work on the other macOS machine. That was the problem.
I created a requirements.txt on the first macOS machine, then I created a new env on the other macOS machine, loaded the requirements.txt, and it now works.

Install python pip modules only for use by Ansible

I am using Ansible from a pipeline agent, to configure Ubuntu VMs and I would like to use the azure_rm_storageblob and mssql_script module directly on the Ubuntu VM that I am configuring. I had some issues running this, because the packaging module was not installed on the hosts.
Is there a way to install the pip modules only for use when I run Ansible (maybe a virtual environment), as I don't want to mess with the pip modules that are installed on the server for other purposes.
If this is done using something like a python virtual env, how do I make sure that this is used when I connect to the VM using Ansible?
You have to use virtual environments to solve that problem (link to the python doc)
First you create the environment with :
python -m venv venv
Then depending on your OS, you have to activate you virtual environment, on Unix you can do :
source venv/bin/activate
The name of you virtual env should be written in your terminal, at that point you know you are using it and not the default python env.

Illegal Instruction: 4 from python [duplicate]

I've been using Python 2.7.10 in a virtualenv environment for a couple of months.
Yesterday, activating the environment went fine, but today suddently I get this cryptic error when trying to start Python from Terminal:
Illegal instruction: 4
I have made no changes to my environment (AFAIK), so I'm having a difficult time trying to come to terms with what this error is and what caused it.
Python works fine outside of this virtualenv environment. When running via /usr/local/bin it presents no problem.
I've had this problem a number of times now. While I can't say for certain what the actual issue is, I believe it basically means that some file(s) in the virtualenv installment of Python have become corrupted.
I keep my virtual environment in a synced Dropbox folder, so that may be a large contributor to the issue.
Restoring the virtual environment from a back-up archive worked for me. Or simply reinstall an identical virtual environment.
First, try activating the faulty environment by cd <path/to/old_env> and source /bin/activate.
If it's successfully activated, cd to an accessible location on the drive and run pip freeze > requirements.txt to export a list of currently installed Python modules.
Delete the old environment.
Install a new virtual environment of the latest version of Python 2 that you have on the computer, via virtualenv <path/new_env>
Or, if you want to use a specific Python version, first make sure you have you have it on your drive, and then do virtualenv -p <path>. Assuming that you have downloaded the Python version with Homebrew, e.g.: virtualenv -p /usr/local/bin/python2.6 <path/new_env>
Activate the virtual environment via cd <path/new_env> and then do source /bin/activate.
Assuming that you kept a list of modules to reinstall by previously doing pip freeze > requirements.txt, cd to the folder where the text file is located and do pip install -r requirements.txt.
Otherwise, reinstall the modules with pip manually.
I had same problem and found solution by uninstalling psycopg2 and installing older version. As I understood my comp was not supporting some commands in new version

problems creating virtualenv when installing two different versions of Python

I have installed Python 2.7, pip and virtualenv on my computer and I have created a virtual environment with this same version of Python. I installed some packages in this new virtual environment too.
Later, I decided to install Python 3.6 on the same computer to create a virtual environment that works with version 3.6. I downloaded Python 3.6 and installed it by selecting Add Python 3.6 to PATH and Install for All users and I selected the option to automatically install pip. As I had previously installed virtualenv, I have not had to reinstall it. Should I?
The problem is that, once installed, when creating a virtual environment I've got an error.
As I already had a version of Python installed I have specified that I want to use Python 3.6 in the virtual environment that I am creating:
virtualenv env2_py36 -p c: \ Python36 \ python.exe
The error already says that this usually happens when you install more than one version of Python on the same computer and warns that it is necessary to check the option Install for All Users to work (as I did) and also recommends placing the appropiate PythonXX.dll file in the Scripts folder of the virtual environment. However, I see that there is already a python36.dll file there.
Could anybody tell me what should I do to fix this problem?
On the other hand, I had previously created another virtual environment using Python 2.7. I use PyScripter to run my scripts but I don't know how to connect PyScripter to my virtual environment. It's still connected to the Python2.7's system installation.
This works for me:
virtualenv --python=python3.6 yourenvname
(3.6 is the current latest version of Python, but you can use whichever version you'd like.)

when I pip install, my packages are going in my macs local library

when I pip install a package it gets insalled on my macs library. I am using pycharm whih allows me to click on a package like a hyperlink. And instead of going to my site-packages in my virtualenv it's going to my macs library which is
/Library/Frameworks/Python.Framework/Versions/3.5/lib/python3.5/site-packages/gdata/youtube/
when it should be
myproject/lib/python3.5/site-packages/gdata/youtube/
why is that.
You should activate your virtual environment to install packages on that. In Pycharm you can do it like this:
Go to File > Settings > Project > Project Interpreter
Now you have to select the interpreter for this project. Browse or select the interpreter from drop-down if available. In your case this should be:
myproject/lib/python3.5
I am using Pycharm community edition on Ubuntu. But the
process should be similar in Mac.
I think you want to create a virtual environment for your project.
Install this tool virtualenv.
$ pip install virtualenv
Then create your project's folder
$ cd my_project_folder
$ virtualenv venv
This creates a copy of Python in whichever directory you ran the command in, placing it in a folder named venv.
Source
https://github.com/pypa/virtualenv
For further knowledge read
https://realpython.com/blog/python/python-virtual-environments-a-primer/
You should install your virtual environment and then run pip within that environment. So, for example, I use Anaconda (which I thoroughly recommend if you are installing alot of scientific libraries).
To activate the environment "hle" I type in:
source /Users/admin/.conda/envs/hle/bin/activate hle
Once I've done this the pip command will reference the virtual environment location and not the standard mac location. So, when I install "mypackage" as follows:
pip install mypackage
It subsequently installs files in the virtual folder and not in the usual mac system folders.
You can find out about the Anaconda virtual environment (and download it) over here: http://conda.pydata.org/docs/install/quick.html but other virtual environments (like Virtualenv) work in the same way.

Categories