Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Couldn't create working virtual environment for Python 3.4

I installed Python 3.4.2 and Virtualenv 12.0.5 in my Linux Mint 17.1

Then I tried creating: $ virtualenv venv

And also using --clear and/or -p /usr/bin/python3.4, always getting the messages:

Using base prefix '/usr' New python executable in venv/bin/python3 Also creating executable in venv/bin/python ERROR: The executable venv/bin/python3 could not be run: [Errno 13] Permission denied

Another try was: $ pyvenv-3.4 venv

It gave no errors on creation, but in the venv/bin file the python3.4 is a symbolic link to /usr/local/bin/python3.4. Then when I activate and install any lib using pip or pip3, then try to import it, I get the error: Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named 'anymoduledownloaded'

I always used virtualenv in Python 2.X and never got this kind of errors. Any thoughts on what am I doing wrong?

Thanks!!

=======EDITED=======

This is the output of my partitions (fdisk -l):

Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    98707455    49352704   83  Linux
/dev/sda2       303507456  3890644991  1793568768    5  Extended
/dev/sda3   *    98707456   303507455   102400000    7  HPFS/NTFS/exFAT
/dev/sda4      3890644992  3907028991     8192000   82  Linux swap / Solaris
/dev/sda5       303509504  3890644991  1793567744    7  HPFS/NTFS/exFAT`

And also my fstab:

<file system> <mount point>   <type>  <options>       <dump>  <pass>
-> was on /dev/sda1 during installation
UUID=a38f9c6d-3cd9-4486-b896-acbc6182ec61 /               ext4    errors=remount-ro 0       1
-> swap was on /dev/sda4 during installation
UUID=efad7b53-79a8-4230-8226-9ca90c68ea9d none            swap    sw              0       0`
like image 265
staticdev Avatar asked Jan 07 '15 22:01

staticdev


People also ask

What is the Python 3.3 tool for creating virtual environment?

If you are using Python 3.3 or newer, the venv module is the preferred way to create and manage virtual environments. venv is included in the Python standard library and requires no additional installation.


2 Answers

Is that a shared partition that you have mounted? Does the shared partition have a different filesystem then the non-shared one you tried upon? If yes, then IMO, that will definitely cause an error since you are making and compiling binaries for python on one filesystem, and so it will not work on another filesystem.

As mentioned in this answer, adding to your /etc/fstab with an entry with exec flag might make it work for you, i.e., you might need to add another entry for the NTFS disk here to make it automount:

<file system> <mount point>   <type>  <options>       <dump>  <pass>
-> was on /dev/sdaX during installation
UUID=<uid_of_NTFS> /     ntfs    auto,user,exec,nodev,rw,errors=remount-ro 0       1
like image 158
Anshul Goyal Avatar answered Sep 19 '22 03:09

Anshul Goyal


I struggled with this as well so I wrote an ugly bash script to help me with this. The only salient difference between what you do and what I do is on line 133:

/path/to/python/bin/python3.4 /path/to/python/bin/pyvenv /path/to/venv

That is, explicitly name the instance of python and the venv tool. Then

/path/to/venv/bin/pip install django # or whatever

Edit

I installed Linux Mint in a VM to try and build a Python 3.4 virtual environment. Based on the error messages I saw and this answer, I learned that I must do the following to get a complete Python 3.4 build:

apt-get install build-essential libssl-dev openssl

Without this, my Python 3.4 build did not contain pip. Note that you probably want to install readline and other development packages.


Unsolicited Advice

  1. Do not do this as root, create a user dedicated to running your venv
  2. Create a script to create your environment
  3. Check that script into your source code repo

I deleted my python binaries and venvs multiple times and then recreated all of with this script to make sure that my script reproduced my environment and then stripped the identifying information and saved that on github to share it. I should really be using a more formal tool for this like docker/puppet/chef.

like image 39
John Schmitt Avatar answered Sep 19 '22 03:09

John Schmitt