简体   繁体   中英

mkvirtualenv gives permission denied error

When running: mkvirtualenv test

I get following error:

  File "/usr/lib/python3/dist-packages/virtualenv.py", line 2378, in <module>
    main()
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 830, in main
    symlink=options.symlink)
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 999, in create_environment
    site_packages=site_packages, clear=clear, symlink=symlink))
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 1198, in install_python
    mkdir(lib_dir)
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 451, in mkdir
    os.makedirs(path)
  File "/usr/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/usr/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/usr/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: 'test'

Why is the 'test' virtual environment not created? I did try to chmode -R 777 the virtualenv folder, but that did not solve it. I do have python 2.7 and 3.4 installed on Ubuntu 15.04

You are likely getting the error because you cannot create the virtualenv folder in the current working directory.

If you do an ls -ld . you'll see the output of the current directory you're running the command from, eg:

➜  ~  ls -ld .
drwxr-xr-x+ 114 tfisher  staff  3876 Jun 26 08:46 .

and if you do a whoami , you'll get the name of your current user.

The interesting bit in the output is typically the first portion of that ls -d . command: drwxr-xr-x+ . This means "this is a directory, with Read, Write, eXecution for the user, then Read eXecute for the group, and finally Read and eXecute for everyone else."

If you do not have w rite permission, you will not be able to create the files and folders that virtualenv needs.

If the current directory is one that you feel that you should personally own, eg /home/musicformellons , and you have sudo permission, you can rectify this by running:

sudo chown `whoami` .

The reason why this didn't just simply work is likely because you followed a guide that had you install a "virtualenvwrapper" using sudo permissions.

i have did the same the issue i found is :

echo $WORKON_HOME

you will find : /home/user/.virtualenvs/extra_path

just yoy need to remove this extra_path added after .virtualenvs path from your .bashrc and then source it again try again creating mkvirtualenv

我认为您无法创建测试virtualenv。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM