5

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`
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
staticdev
  • 2,950
  • 8
  • 42
  • 66
  • How did you install Python 3? Can you run `ls -lLa $(which python3)` – Thomas Orozco Jan 07 '15 at 22:41
  • I followed to python docs: ./configure; make; sudo make install; Command result: -rwxr-xr-x 2 root root 11598453 Jan 7 19:20 /usr/local/bin/python3 – staticdev Jan 08 '15 at 23:16
  • 1
    @StaticX Is that a shared partition that you have mounted? Check [this answer](http://stackoverflow.com/a/14761023/1860929). – Anshul Goyal Jan 12 '15 at 14:11
  • @mu 無 it certainly has to do with the shared partition. I tried on a non-shared partition and worked. But, I couldn't find this partition mounted in /etc/fstab. – staticdev Jan 14 '15 at 22:41
  • @StaticX 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. – Anshul Goyal Jan 15 '15 at 07:13
  • @StaticX Also, can you add the output of `sudo fdisk -l` to the question? – Anshul Goyal Jan 15 '15 at 07:20
  • @mu 無 answer edited for the outputs. The shared partition is a NTFS and the non-shared is EXT4. But, when I create a new environment the binaries are recompiled? Does the binaries depend on the filesystem? (I thought it only depended on the system instructions architecture - I am not very good at compilers interns). Shouldn't NTFS run on Linux because of the compatibility layers? – staticdev Jan 15 '15 at 23:00
  • I don't know if it can solve your problem, but have you considered using [pyvenv](https://docs.python.org/3/library/venv.html) from the python3 standard library. It's more or less an improved version of virtualenv. – Håken Lid Jan 15 '15 at 23:50
  • @Håken Lid I tried that, as shown in my answer. – staticdev Jan 18 '15 at 23:56
  • @mu 無 please put the shared partition as the answer for me to give you the bounty. – staticdev Jan 18 '15 at 23:57

2 Answers2

4

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.

Community
  • 1
  • 1
John Schmitt
  • 1,148
  • 17
  • 39
  • Nice script, but still didn't solve my problem. I also forked and updated the Python and Django versions for you on GitHub. Thanks anyhow! – staticdev Jan 14 '15 at 22:33
  • Actually, your script uses RPM (mkenv3: line 17: rpm: command not found).. and I am using Debian. But I already know that it has something to do with shared partition as @mu 無 wrote above. We could work out a way for this script being compatible with multiple distributions. – staticdev Jan 14 '15 at 22:50
4

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
Community
  • 1
  • 1
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
  • This change had just crashed my system, turning it to a readonly filesystem. I couldn't open most of my programs and had to use a linux live-dvd to change back /etc/fstab. – staticdev Jan 18 '15 at 15:02