scikit-learn joblib: Permission error importing, run in Serial mode - python

The following permission error occurs when I try importing joblib from script or python -c 'import joblib':
/usr/local/lib/python2.7/dist-packages/joblib//joblib_multiprocessing_helpers.py:29: UserWarning: [Errno 13] Permission denied. joblib will operate in serial mode
warnings.warn('%s. joblib will operate in serial mode' % (e,))
joblib is installed and forcefully reinstalled via pip
importing works as superuser
I set full permissions on the joblib folder chmod -R 777 /usr/local/lib/python2.7/dist-packages/joblib; to no avail: the permission error remains
So even though every user and group has full rwx permissions on the joblib directory it gives me a permission error. How do I figure out on which directory joblib does the write permission check when importing? Why does it even do the check before I specified a write operation?

Found it by looking a in the joblib source code:
The problem was that semaphoring was not enabled on my system: Joblib checks for multiprocessing.Semaphore() and it turns out that only root had read/write permission on shared memory in /dev/shm. Fixed it as per this answer by permanently setting the correct permissions (even after a reboot) by adding the following to your /etc/fstab:
none /dev/shm tmpfs rw,nosuid,nodev,noexec 0 0 and then remount mount /dev/shm -o remount

Related

Server Error while saving panda dataframe to csv

part of my python script is as below
panda_dataframe.to_csv("myfile.csv")
The code is working fine in my Dev System.
I have deployed it in EC2 - Ubuntu. The above statement return Server Error (500)
I have also tried with
panda_dataframe.to_csv("/usr/share/myfile.csv")
But the same error.
Error.log has the below error.
PermissionError: [Errno 13] Permission denied: '/usr/share/myfile.csv'
I have tried with setting the below permisions
sudo setfacl -m u:www-data:rw /var/www/sitefolder/myfile.csv
sudo setfacl -m g:www-data:rw /var/www/sitefolder/myfile.csv
Guide me what is the permission I have to assign to write the dataframe into a csv file
Your working directory is /usr/share, and saving/deleting/copy/move actions in /user directory requires sudo privileges. so first check you user directory by executing echo $HOME. say the result is /home/amir. now save you data frame as:
panda_dataframe.to_csv("/home/amir/myfile.csv")

pip install is not working and I cannot upgrade setuptools?

I am trying to upgrade setuptools to ver 18.5 or more so that I can install these libraries: html5lib, lxml, lxml.cssselect, & requests. So I'm attempting to do this by entering:
curl https://bootstrap.pypa.io/ez_setup.py -o - | python in the command line. However, this gives me the following error. I am using Mac OSX..
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 12402 100 12402 0 0 49481 0 --:--:-- --:--:-- --:--:-- 49608
Extracting in /var/folders/wt/9y2d_zh12r98sn0416p0yjs00000gn/T/tmpvS6bWN
Now working in /var/folders/wt/9y2d_zh12r98sn0416p0yjs00000gn/T/tmpvS6bWN/setuptools-27.3.0
Installing Setuptools
running install
error: can't create or remove files in install directory
The following error occurred while trying to add or remove files in the
installation directory:
[Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-17438.write-test'
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/Library/Python/2.7/site-packages/
Perhaps your account does not have write access to this directory? If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account. If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.
For information on other options, you may wish to consult the
documentation at:
https://setuptools.readthedocs.io/en/latest/easy_install.html
Please make the appropriate changes for your system and try again.
Something went wrong during the installation.
See the error message above.
Any help would be appreciated!Thanks

Chmod in Python - [Errno 1] Operation not permitted

I'm trying to modify an application in my /Applications folder on OS X. I need to get read and write permissions, so I currently have:
os.chmod(appDir, 0644)
where appDir is the directory of my app. However, whenever I run the program, I get the error:
OSError: [Errno 1] Operation not permitted: '/Applications/Simplenote.app'
I would try sudo, but how would you enter the password through Python? (this is a Python script by the way)
Any help is appreciated.
If you are trying to run the script from a web site, change the target folders/files to be owned by the web user, e.g. www-data. sudo chown www-data * -R That fixed it for me.

Fabric get( ) permission denied with use_sudo=True

With the fabric function:
def get_test():
get("/home/wagans/test.txt", "/wagans/test.txt", use_sudo=True)
I'm getting a 'Permission denied' error.
Full error:
Fatal error: get() encountered an exception while downloading '/home/wagans/test.txt'
Underlying exception:
Permission denied
Aborting.
Disconnecting from root##########... done.
get() encountered an exception while downloading '/home/wagans/test.txt'
Underlying exception:
Permission denied
I was connecting as a specific user, but tried connecting as root and still received the same result.
Output of "ls -l" on the remote_path are:
-rwxrwxrwx 1 root www-data 10 May 4 13:21 test.txt
Output for local path folder is:
drwxr-xr-x 9 user 306 3 May 17:56 wagans
The remote machine is Ubuntu 14.04, and local is OSX with fabric running in a virtualenv.
Can anyone help guide me to a solution?
Many thanks.
You're certainly trying to use the rights of sudo in a script launched from your simple-user-rights. So, you must launch the script using the sudo command.
I got a very similar error and found the solution:
"yourfile.py" [New File]
Fatal error: get() encountered an exception while
downloading '/home/youruser/foobar'
Underlying exception:
Operation not supported
Aborting.
The solution was not to store files in my home directory which has restricted permissions, you have to store and retrieve files in a open permissions directory like /tmp
Here is the code that works:
from fabric.operations import get
def fabric_ssh(ip_address, user, password, key_path, verbose=True):
return settings(
host_string=ip_address,
user=user,
key_filename=key_path,
parallel=False,
warn_only=False)
with fabric_ssh("10.0.0.3", "your_user",
"Yourpassword",
"yourkeypath",
True):
get("foobar","/tmp/")
Finally it prints a success message after downling:
[10.130.28.191] download: /tmp/foobar <- /home/youruser/foobar

OSError - Errno 13 Permission denied

I am trying to upload image through admin page, but it keeps saying:
[Errno 13] Permission denied: '/path/to/my/site/media/userfolder/2014/05/26'
the folders userfolder/2014/05/26 are created dynamically while uploading.
In Traceback, i found that the error is occuring during this command:
In /usr/lib64/python2.6/os.py Line 157. while calling
mkdir(name, mode)
meaning, it cannot create any folder as it doesnot have the permission to do this
I have OpenSuse as OS in Server. In httpd.conf, i have this:
<Directory /path/to/my/site/media>
Order allow,deny
Allow from all
</Directory>
Do I have to chmod or chown something?
You need to change the directory permission so that web server process can change the directory.
To change ownership of the directory, use chown:
chown -R user-id:group-id /path/to/the/directory
To see which user own the web server process (change httpd accordingly):
ps aux | grep httpd | grep -v grep
OR
ps -efl | grep httpd | grep -v grep
This may also happen if you have a slash before the folder name:
path = '/folder1/folder2'
OSError: [Errno 13] Permission denied: '/folder1'
comes up with an error but this one works fine:
path = 'folder1/folder2'
Probably you are facing problem when a download request is made by the maybe_download function call in base.py file.
There is a conflict in the permissions of the temporary files and I myself couldn't work out a way to change the permissions, but was able to work around the problem.
Do the following...
Download the four .gz files of the MNIST data set from the link ( http://yann.lecun.com/exdb/mnist/ )
Then make a folder names MNIST_data (or your choice in your working directory/ site packages folder in the tensorflow\examples folder).
Directly copy paste the files into the folder.
Copy the address of the folder (it probably will be
( C:\Python\Python35\Lib\site-packages\tensorflow\examples\tutorials\mnist\MNIST_data ))
Change the "\" to "/" as "\" is used for escape characters, to access the folder locations.
Lastly, if you are following the tutorials, your call function would be ( mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) ) ;
change the "MNIST_data/" parameter to your folder location. As in my case would be ( mnist = input_data.read_data_sets("C:/Python/Python35/Lib/site-packages/tensorflow/examples/tutorials/mnist/MNIST_data", one_hot=True) )
Then it's all done.
Hope it works for you.
Another option is to ensure the file is not open anywhere else on your machine.
supplementing #falsetru's answer : run id in the terminal to get your user_id and group_id
Go the directory/partition where you are facing the challenge.
Open terminal, type id then press enter.
This will show you your user_id and group_id
then type
chown -R user-id:group-id .
Replace user-id and group-id
. at the end indicates current partition / repository
// chown -R 1001:1001 . (that was my case)
Simply try:
sudo cp /source /destination
Just close the file in case it is opened in the background. The error disappears by itself
The solution that worked out for me here when I was using python 3 os package for performing operations on a directory where I didn't have sufficient permissions and access to got resolved by running the python file with sudo (root) i.e.:
sudo python python_file_name.py
Any other utility that you might also plan on using to chmod or chown that directory would also only work when you run it with sudo.
# file_name.py
base_path = "./parent_dir/child_dir/"
user = os.stat(base_path).st_uid # for getting details of the current user owner of the dir
group = os.stat(base_path).st_gid # for getting details of the current group owner of the dir
print("Present owner and group of the specified path")
print("Owner:", user)
print("Group:", group)
os.chown(base_path, user, group) # change directory permissions
print("\nOwner id of the file:", os.stat(base_path).st_uid)
print("Group id of the file:", os.stat(base_path).st_gid)
os.mkdir(base_path+file_name,mode=0o666)
run the above file with sudo.
sudo python file_name.py
Hope this answer works out for you.
Forever indebted to stackoverflow and the dev community. All hail the devs.

Categories

Resources