Virtualenv permission denied - bash

After a lot of struggle with virtualenv/virtualenvwrapper I decided to remove all virtualenvs and re-install the packages.
root> su myuser
myuser> sudo pip install virtualenv
myuser> sudo pip install virtualenvwrapper
I proceeded to add this to my unix users .bashrc file.
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python2.7
source /usr/local/bin/virtualenvwrapper.sh
When I source .bashrc I get about 20 error lines ending with IOError: [Errno 13] Permission denied: '/root/.virtualenvs/premkproject'. I'm running out of ideas...
I have done my homework and tried every suggested solution I could find. I'm running Ubuntu 12.04.

I had the same problem and it was due to .virtualenvs having owner and group root. So the following would fix it (substituting ubuntu:ubuntu for your user and groups):
cd ~
sudo chown -R ubuntu:ubuntu .virtualenvs/
I used the recursive option as I had a problem installing a package with pip and that was due to a file lower down the hierarchy also having a permissions problem.

You never explained in which SO are you working...So if you are in Mac OS X you can easily fix it by giving eXecute permissions.
I believe Linux may face the very same problem altought I myself never got this problem under Linux.
The 'magic words' are the following :
chmod 755 <your path>/virtualenv.py

Related

Why do I always get a permission issue when trying to install python packages?

Whenever I try to install packages through homebrew or pip, it gives me a permission error. (I'm using macOS Catalina)
I somewhat got pip to work by using the "sudo -H" prefix. It downloads them successfully but then when I attempt to import them in Python, it tells me the module wasn't found. Earlier today I changed the default version of Python to 3.8.2, but the same error was happening way before that.
Here's the Homebrew command I used:
brew install libyaml
Here's what it's returning:
Error: Permission denied # apply2files - /usr/local/lib/node_modules/json-server/node_modules/term-size/vendor/macos/.DS_Store
you need to check user permissions on the first /usr, /usr/local, and /usr/local/lib directories. you need rwx permissions to write content in these folder. Failing this permission on any folder will not allow you to modify content in /usr/local/lib.
you can use sudo chmod u+rwx folder_name to provide read write execute on the folders. If you want to providerwx permission to all folder inside /usr use sudo chmod u+rwx -R /usr

Unable to Install postgresql on my mac os x machine via homebrew

I was trying to install the postgres through terminal on mac os. I used homebrew to install the postgres.
During the install I got following error
"Error: The brew link step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/man/man3/SPI_connect.3"
I also got error regarding initdb
"initdb: file "/usr/local/share/postgresql/postgres.bki" does not exist
This might mean you have a corrupted installation or identified
the wrong directory with the invocation option -L.
Warning: The post-install step did not complete successfully
You can try again using brew postinstall postgresql"
After the install I am not able to run any of postgres commands. I would really appreciate any help as I am new to postgres. Please, provide little explanation.
Thank You!
Not sure if this solution is the best, but so far this is the only one.
Note: I did this on a macOS environment
I have chowned the directory I wasn't allowed to write. (chown -R user/usr/local/lib/pkgconfig)
/usr/local/lib/pkgconfig` (assumed that dir should be mine anyway - since it's within /usr/local)
I ran
brew link postgres - so the links required are there
Then initdb /usr/local/var/postgres -E utf8 worked perfectly.
Running brew postinstall postgres --debug gives:
Errno::EACCES: Permission denied # dir_s_mkdir - /usr/local/var/postgres
Creating the directory manually and setting the right group worked:
cd /usr/local/var
sudo mkdir postgres
sudo chown <user> postgres
sudo chgrp admin postgres/

vagrant: command not found after install on Mac OSX 10.10.4

Downloaded Vagrant, and went through th installation process.
When I ran vagrant -v it says vagrant: command not found
It has put the files in /opt/vagrant/...
It should install in the Applications folder with a link to the /usr/bin so it is added to the shell path.
There is no directory that has been created during this process.
I am afraid I can't even get started with it. ITs obviously not creating all the shortcuts it needs to be able to run the commands.
I have looked for support on this issue and reported a bug.
I also accepted the xcode licence agreement.
Has anybody else had this issue.
My next step is to manually create the shortcuts.
If you look at the uninstall script including in the Vagrant DMG, it is referring to /usr/local/bin which does not exist. It should be error handling (the Vagrant pkg installer) and create it (permissions/ownership etc) but it doesn't.
You need to mkdir the /usr/local/bin. I tried a symlink between /usr/bin/vagrant (as /usr/bin exists, and in-path) to /opt/vagrant/bin/vagrant BUT this does not work, as later on in life, Vagrant refers in a hard fashion to /usr/local/bin/vagrant because its stupid.
$ sudo mkdir /usr/local/bin
If you sudo it, it should be made with correct ownership etc. Now just re-run the Vagrant installer pkg.
Make sure the Virtual Box setup is installed on Mac before installing Vagrant.
I raised the bug with https://github.com/mitchellh/vagrant/issues/6034
The issue is that I had no /usr/local directory at all.
It is an apple issue.
After I created the directories as you described I was able to install vagrant vitrual boax and laravel.
Here is what I did.
sudo mkdir /usr/local
Then bin.
cd /usr/local
sudo mkdir bin
I uninstalled Vagrant, re-installed and when I ran vagrant -v I then got the version.
cd /usr/local/bin
ls
sudo chmod 755 vagrant
Thanks for your Answer.
Weird, on 1.8.5 I couldn't run Vagrant either, noticed that /usr/local/bin was owned by root. Ran command
# chown -R User:Group /usr/local/bin
as root and works from my username now.

brew install - permission denied (after chown -R `whoami` )

$ brew install fontconfig
Error: Permission denied - /Library/Caches/Homebrew/Formula/fontconfig.brewing
$ sudo chown -R `whoami` /usr/local
$ brew install fontconfig
Error: Permission denied - /Library/Caches/Homebrew/Formula/fontconfig.brewing
Not sure where to go from here. Ran brew doctor to fix some existing issues, but can't seem to get past this.
trojanfoe's answer helped. There was a permission issue with the Library/Logs folder that I wasn't assigned to, but somehow the Library/Caches/Homebrew folder didn't exist. So I just created that, the subfolder Formula, and changed the permission and everything installed just fine. It actually cleared up a lot of errors I was having.
Thanks everyone.
Update
#fet's one liner works great.
mkdir -p ~/Library/Caches/Homebrew/Formula
For others that are running into the error of something like
$ brew upgrade
==> Upgrading 1 outdated package, with result:
libtool 2.4.6
==> Upgrading libtool
Error: Permission denied - /usr/local/lib/libltdl.7.dylib
Make sure that your directory, in this case /usr/local/lib, has sufficient permissions for you to access it. I ran into the issue where it was only assigned to root:admin.
$ ls -la /usr/local/lib/ | grep "libltdl.7"
lrwxr-xr-x 1 username admin 43 Oct 12 2014 libltdl.7.dylib -> ../Cellar/libtool/2.4.2/lib/libltdl.7.dylib
Switched that to myusername:admin and was able to upgrade with no problems.
cd /usr/local/lib
sudo chown `whoami`:admin .
Hope that helps!

Installing in Homebrew errors

Attempting to install rvm and ruby 1.9.2
I already installed homebrew and git, but couldn't get complete updates because I kept getting permission errors. Re-installed Snow Leopard and repaired permissions.
Now this happens...
$ brew install wget
Error: Cannot write to /usr/local/Cellar
sudo chown -R $USER /usr/local
You'll have to give yourself ownership of /usr/local/ using that line right there. I had to do this myself after using the ruby one-liner at the top of the official docs to install Homebrew. Worked like a charm for me. It ought to be the only time you'll ever need to sudo with Homebrew.
I'm not sure if the ruby one-liner does this. If it did, then something else on my system took control of /usr/local since.
Edit: I completely missed this, but #samvermette didn't (see replies to my answer): if you run this command above and have something installed via homebrew that requires special user permissions, like mysql, make sure to give those permissions back (as the above command gives recursive ownership to everything inside /usr/local to you ($USER). In the case of mysql, it's…
sudo chown -RL mysql:mysql /usr/local/mysql/data
I had this issue after upgrading to Mavericks, and this page was the top search result when googling the error message. I continued searching and found this answer on stack overflow.com. Put concisely, it is:
sudo chmod a+w /usr/local/Cellar
This fixed the issue for me, and as it only changes permissions for the specific path referenced in the error message, seemed unlikely to have negative side effects with other installations.
I'm putting this answer here for anyone else who may find this page first like I did. However, credit should go to jdi.
You can allow only Admin users writing into /usr/local/?
chgrp -R admin /usr/local
chmod -R g+w /usr/local
chgrp -R admin /Library/Caches/Homebrew
chmod -R g+w /Library/Caches/Homebrew
Since that each user who belongs to Admin group, will be able to install new dependencies.
On High Sierra you need the following command cause chown will not work:
sudo chown -R $(whoami) $(brew --prefix)/*
Link:
https://github.com/Homebrew/brew/issues/3228
uninstall and re install HomeBrew that will do the trick
I suggest ensuring that the current user is a member of the group that owns /usr/local. I believe by default, that group is wheel. To make yourself a member of that group:
$ sudo dscl . append /Groups/wheel GroupMembership $USER
Although something of an inelegant hammer, it has the intended effect - enabling access to items in /usr/local that are intended only for use (read/write) by elevated members. This approach has benefits of the other above because it takes advantage of the group memberships, enabling multiple (authorized) users on the system to use homebrew.
How did you install Homebrew? Their official installation instructions include running a ruby script. That should take care of the permission issues for you.
If you don't want to run a script, there is a section of that page called "Installing to /usr/local for Developers" that explains the change in permissions needed for the /usr/local directory.
EDIT: As mentioned in the comments it's a bad idea to use sudo with homebrew, so don't use the following answer!
You can also prevent this error if you execute the command with sudo:
$ sudo brew install wget
But take care of using sudo because you can make a lot of mistakes.

Resources