File permissions issue with python/Spyder/Anaconda after upgrading mac to Catalina - python

After upgrading macOS to Catalina, my Anaconda installation was helpfully reconfigured by Apple. Advice from the Anaconda website suggested a fresh install was the best way to go. Did that and all seemed good. I use spyder from the Anaconda navigator. But trying a previously running python code failed due to apparent file permission problems. For example,
file='/Users/stingay/Documents/Coaching/WAIS/2019:20/041019/Race Walk Test-2019-10-04T16.29.13.774-C5612E80FB1D-Accelerometer.csv'
with open(file,'rt') as f:
data = csv.reader(f)
next(data)
results in:
PermissionError: [Errno 1] Operation not permitted: '/Users/stingay/Documents/Coaching/WAIS/2019:20/041019/Race Walk Test-2019-10-04T16.29.13.774-C5612E80FB1D-Accelerometer.csv'
I can't see an issue with the permissions on the file or the directory structure in which the file sits. If I move the file to~/.spyder-py3 (the working directory), it works.
Looks like there is some extra python/spyder/anaconda permissions issue with the file/directory I can't spot. Any ideas?

I guess you have solved this by now, but for future reference, I still post my answer.
TLDR: I opened a file (from the folder causing the problem) directly in
the spyder editor (File | open). As a consequence, the editor should have triggered the pop-up dialog question whether you want to allow access or not. In my case, the mac silently granted python/spyder access to the folder. Now I can run the code in spyder without more problems than I have caused myself.
Longer version:
The source of your problem is described here:
https://www.howtogeek.com/443611/how-macos-catalinas-new-security-features-work/
Knowing that links are something frown upon, here's a summary:
The problem is that the folders "Documents" and "Downloads" folders nowadays are protected and you would need to go to the security & privacy settings and "Files and Folder,s" and allow the applications to access these. Unfortunately, spyder does not show up here. So, if you want to run your python program from the terminal, you should probably grant the terminal access to the folders.

Total noob here, but I might have stumbled upon a solution for people that have problems reading in their data in spyder after the Catalina update. I had the same problems you describe and got the same file permission errors.
I couldn't resolve the issue, reinstalled several times but didn't work for me. I couldn't use my Utorrent either, and while attempting to solve that problem I came across https://discuss.pixls.us/t/problems-with-darktable-and-mac-osx-catalina-solved-with-dt-2-6-3-1/14400/19 this forum.
Long story short, in the forum people couldn't really resolve the issue, but someone pointed out that if you just run the application from the terminal, it somehow works. I tried to do this with Spyder, and I seem to be able to use the read_csv('file') function again. So try opening the terminal, then type 'spyder' (without '') and press enter. Somehow all issues seem to be resolved. Hope this helps someone.

Same problem here. I re-installed Anaconda based on this link and Python is able to access folders where Catalina has added newly restricted security:
Install Anaconda following instructions below:
https://www.anaconda.com/how-to-restore-anaconda-after-macos-catalina-update/
For Anaconda-Jupyter user, you are good to go
For Commandline (Terminal) Python user, you are good to go
For Anaconda-Spyder user, two options as a workaround after installation above:
Avoid Mac default setup-folders and relocate files to /Users/[user_name]/..
OR
Launch Spyder through Terminal (execute "sudo spyder") under root user
Lastly, changing or reseting folder/file permission does not resolve permission issue. Despite of the security issue under the more restricted security folders, somehow Spyder-Python is able to open .py files in these folders.
Since Jupyter and commandline Python can access these folders, I assume there will be a fix in the future for Anaconda-Spyder.

My code didn't work at all after Catalina update. The simplest partial solution that I found was to copy all files containing the scripts in a new folder. That works at least to run the codes, but I still dealing with annoying message to allow access to my files.

conda update --all in terminal worked for me. It updated everything. I did have to go through the annoying messages for access to my files as well. but after clicking yes a hundred times it was ab

Related

How do I solve "pythoncom39.dll could not be located error"?

It has started appearing ever since I installed Anaconda on my PC. It doesn't affect anything and when I press "Ok" it goes away. But it is quite annoying and I would like to know the reason. It has only appeared when I try to run a development server in Django or try to install python modules using pip. Is there any way to solve this?
It happens because anacondaa3\Library\bin\ in this folder pythondicom39.dll has crashed you need to replace it with a new file
Yes, that dll file might be corrupted. Just replace, and then try it. You can download the pythoncom39.dll files from the following link
https://freeonlinestudies.com/python-dlls/

ModuleNotFoundError: No module named 'core' while PyCharm can run 'core.py' [duplicate]

I am using PyCharm to work on a project. The project is opened and configured with an interpreter, and can run successfully. The remote interpreter paths are mapped properly. This seems to be the correct configuration, but PyCharm is highlighting my valid code with "unresolved reference" errors, even for built-in Python functions. Why don't these seem to be detected, even though the code runs? Is there any way to get PyCharm to recognize these correctly?
This specific instance of the problem is with a remote interpreter, but the problem appears on local interpreters as well.
File | Invalidate Caches... and restarting PyCharm helps.
Dmitry's response didn't work for me.
I got mine working by going to Project Interpreters, Selecting the "Paths" tab, and hitting the refresh button in that submenu. It auto-populated with something called "python-skeletons".
edit: screenshot using PyCharm 3.4.1 (it's quite well hidden)
There are many solutions to this, some more convenient than others, and they don't always work.
Here's all you can try, going from 'quick' to 'annoying':
Do File -> Invalidate Caches / Restart and restart PyCharm.
You could also do this after any of the below methods, just to be sure.
First, check which interpreter you're running: Run -> Edit Configurations -> Configuration -> Python Interpreter.
Refresh the paths of your interpreter:
File -> Settings
Project: [name] -> Project Interpreter -> 'Project Interpreter': Gear icon -> More...
Click the 'Show paths' button (bottom one)
Click the 'Refresh' button (bottom one)
Remove the interpreter and add it again:
File -> Settings
Project: [name] -> Project Interpreter -> 'Project Interpreter': Gear icon -> More...
Click the 'Remove' button
Click the 'Add' button and re-add your interpeter
Delete your project preferences
Delete your project's .idea folder
Close and re-open PyCharm
Open your project from scratch
Delete your PyCharm user preferences (but back them up first).
~/.PyCharm50 on Mac
%homepath%/.PyCharm50 on Windows
Switch to another interpreter, then back again to the one you want.
Create a new virtual environment, and switch to that environments' interpreter.
Create a new virtual environment in a new location -- outside of your project folder -- and switch to that environment's interpreter.
Switch to another interpreter altogether; don't switch back.
If you are using Docker, take note:
Make sure you are using pip3 not pip, especially with remote docker and docker-compose interpreters.
Avoid influencing PYTHONPATH. More info here: https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000058690-Module-not-found-in-PyCharm-but-externally-in-Python .
If the above did not work for you, but you did find another trick, then please leave a comment.
In my case it was the directories structure.
My project looks like this:
+---dir_A
+---dir_B
+app
|
\-run.py
So right click on dir_b > "mark directory as" > "project root"
You have to mark your root directory as:
SOURCE ROOT (red),
and your applications:
EXCLUDED ROOT (blue).
Then the unresolved reference will disappear. If you use PyChram pro it do this for you automatically.
I find myself removing and re-adding the remote interpreter to fix this problem when Invalidating Caches or Refreshing Paths does not work.
I use vagrant and every once and awhile if I add a new VM to my multi-vm setup, the forwarded port changes and this seems to confuse PyCharm when it tries to use the wrong port for SSH. Changing the port doesn't seem to help the broken references.
If none of the other solutions work for you, try (backing up) and deleting your ~/.PyCharm40 folder, then reopening PyCharm. This will kill all your preferences as well.
On Mac you want to delete ~/Library/Caches/Pycharm40 and ~/Library/Preferences/PyCharm40.
And on Windows: C:\Users\$USER.PyCharm40.
Tested with PyCharm 4.0.6 (OSX 10.10.3)
following this steps:
Click PyCharm menu.
Select Project Interpreter.
Select Gear icon.
Select More button.
Select Project Interpreter you are in.
Select Directory Tree button.
Select Reload list of paths.
Problem solved!
Sorry to bump this question, however I have an important update to make.
You may also want to revert your project interpreter to to Python 2.7.6 if you're using any other version than that This worked for me on my Ubuntu installation of PyCharm 4.04 professional after none of the other recommendations solved my problem.
Much simpler action:
File > Settings > Project > Project Interpreter
Select "No interpreter" in the "Project interpreter" list
Apply > Set your python interpreter again > Click Apply
Profit - Pycharm is updating skeletons and everything is fine.
If you want to ignore only some "unresolved reference" errors, you can also tell it PyCharm explicitly by placing this in front of your class/method/function:
# noinspection PyUnresolvedReferences
You might try closing Pycharm, deleting the .idea folder from your project, then starting Pycharm again and recreating the project. This worked for me whereas invalidating cache did not.
I finally got this working after none of the proposed solutions worked for me. I was playing with a django rest framework project and was using a virtualenv I had setup with it. I was able to get Pycharm fixed by marking the root folder as the sources root, but then django's server would throw resolve exceptions. So one would work when the other wouldn't and vice versa.
Ultimately I just had to mark the subfolder as the sources root in pycharm. So my structure was like this
-playground
-env
-playground
That second playground folder is the one I had to mark as the sources root for everything to work as expected. That didn't present any issues for my scenario so it was a workable solution.
Just thought I'd share in case someone else can use it.
It could also be a python version issue. I had to pick the right one to make it work.
None of the answers solved my problem.
What did it for me was switching environments and going back to the same environment. File->Settings->Project interpreter
I am using conda environments.
Mine got resolved by checking inherit global site-packages in PyCharm
File -> Settings -> Project Interpreter -> Add Local Interpreter -> Inherit global site-packages
I closed all the other projects and run my required project in isolation in Pycharm. I created a separate virtualenv from pycharm and added all the required modules in it by using pip. I added this virtual environment in project's interpreter. This solved my problem.
Geeze what a nightmare, my amalgamation of different StackOVerflow answers:
Switch to local interpreter /usr/bin/pythonX.X and apply
View paths like above answer
Find skeletons path. Mine was (/home/tim/Desktop/pycharm-community-2016.2.3/helpers/python-skeletons)
Switch back to virt interpreter and add the skeletons path manually if it didn't automatically show up.
None of the above solutions worked for me!
If you are using virtual environment for your project make sure to apply the python.exe file that is inside your virtual environment directory as interpreter for the project (Alt + Ctrl + Shift + S)
this solved the issue for me.
In my case the inspection error shows up due to a very specific case of python code.
A min function that contains two numpy functions and two list accesses makes my code inspection give this kind of errors.
Removing the 'd=0' line in the following example gives an unresolved reference error as expected, but readding doesn't make the error go away for the code inspector. I can still execute the code without problems afterwards.
import numpy as np
def strange(S, T, U, V):
d = 0
print min(np.abs(S[d]), np.abs(T[d]), U[d], V[d])
Clearing caches and reloading list of paths doesn't work. Only altering the code with one of the following example patches does work:
Another ordering of the 'min' parameters: schematically S U T V but not S T U V or T S U V
Using a method instead of the function: S[d].abs() instead of np.abs(S[d])
Using the built-in abs() function
Adding a number to a parameter of choice: U[d] + 0.
My problem is that Flask-WTF is not resolved by PyCharm. I have tried to re-install and then install or Invalidate Cache and Restart PyCharm, but it's still not working.
Then I came up with this solution and it works perfectly for me.
Open Project Interpreter by Ctrl+Alt+S (Windows) and then click Install (+) a new packgage.
Type the package which is not resolved by PyCharm and then click Install Package. Then click OK.
Now, you'll see your library has been resolved.
In PyCharm 2020.1.4 (Community Edition) on Windows 10 10.0. Under Settings in PyCharm: File > Settings > Project Structure
I made two changes in Project Structure:
main folder marked as source and
odoo folder with all applications I excluded
Screenshot shows what I did.
After that I restarted PyCharm: File > Invalidate Caches / Restart...
Unresolved references error was removed
Invalidating the cache as suggested by other answers did not work for me. What I found to be the problem in my case was that PyCharm was marking init.py files of Python packages as text and thus not including them in the analysis which means python resolving was not working correctly.
The solution for me was to:
Open PyCharm settings
Navigate to Editor -> File Types
Find Python and add __init__.py to the list of python files
or Find Text and delete __init__.py from the list of text files
To add yet another one: None of the solutions involving the Python Interpreter tab helped, however, I noticed I had to set Project Dependencies: In the project that had unresolved reference errors, none of the dependencies were checked. Once I checked them, the relevant errors disappeared. I don't know why some are checked to begin with and others are not.
If you are using vagrant the error can be caused by wrong python interpreter.
In our vagrant we are using pyenv so I had to change Python Interpreter path path from /usr/bin/python to /home/vagrant/.pyenv/versions/vagrant/bin/python
I have a project where one file in src/ imports another file in the same directory. To get PyCharm to recognize I had to to go to File > Settings > Project > Project Structure > select src folder and click "Mark as: Sources"
From https://www.jetbrains.com/help/pycharm/configuring-folders-within-a-content-root.html
Source roots contain the actual source files and resources. PyCharm uses the source roots as the starting point for resolving imports
I had to go to File->Invalidate Caches/Restart, reboot Ubuntu 18.04 LTS, then open Pycharm and File-> Invalidate Caches/Restart again before it cleared up.
For me it helped:
update your main directory "mark Directory as" -> "source root"
#kelorek works for me, but before, in interpereter paths I had to add some path.
lets say
from geometry_msgs.msg import Twist
is underline as error, then in remote machine in python run:
help("geometry_msgs")
at the end there will be path lets say :
/opt/ros/foxy/lib/python3.8/site-packages/geometry_msgs/__init__.py
so to Your intepreter pycharm path add
/opt/ros/foxy/lib/python3.8/site-packages
Hope it will help You and it helps me :)
I had the same symptoms. In my instance the problem source was that I had set
idea.max.intellisense.filesize=50 in the custom properties.
I could resolve it by setting it to 100.
Help->Edit Custom Properties

How to download python linter in vscode with this error

its a very dummy question but i couldn't figure it out. When i try to download a linter from vscode the problem shows up
C:\Users\burak kaya\AppData\Local\Programs\Python\Python37\python.exe: can't open file 'c:\Users\burak': [Errno 2] No such file or directory
The problem occurred due to the whitespace in my folder(Which is automatically created by Windows and i couldn't change it)
I tried to change my user name and the folder name is still same and need to download the linter.
I download linter with pip but vscode don't see that. It still asking to install a linter to me.
So you can't just change the name of the folder and call it a day. Changing the username and folder on Windows is a bit more involved and requires you to modify the registry. Here's a quick video that gives instructions. I've done this twice.
https://www.youtube.com/watch?v=w5N2aaiToiQ
At the beginning, when he says you need to create a local user account, you don't need to do that. The user is already created which, for you, appears to be burak kaya.

How to Give Python Permission to Write Files

I'm learning Python and don't quite have the vocabulary to describe this. However, I can't seem to save files created in Python to my Window10 computer. I discovered this while seeking a help to try to get a file to save in Pandas. I then discovered the same problem when creating a db using SQLITE3 the script seemed to have fun but no database files appeared.
Does anyone know how to fix this? FYI I've got a dual boot Ubuntu machine, I can save files via Python in Ubuntu but really need it to work on my windows machine too.
I am running python via Jupyter Notebook.
I had to make a couple changes to the code snipped that you linked in order to get this to work.
A difference between windows and linux is the file path deliminator is a forward slash:
df.to_csv("tests/ysi_test_files/filehere.csv", index = False)
If you want a hard absolute path to a file, then do something like:
df.to_csv('C://Folder//myfilename.csv', index=False)
Again, if you copy the folder path from a windows folder you will get the backslashes instead of forward slashes. You will need to change those in your code to save the file:
C:\Users\myuser\Desktop\python\
to
C:/Users/myuser/Desktop/python/
If you are running the python script from command prompt then right click on it and run as administrator should solve the issue.

Spyder: [Errno 2] No such file or directory

I want to run this code in Github : https://github.com/llazzaro/lsa_python
but I don't know how to execute it with nosetests. I have python 2.7.11 and anaconda 4.0.0, I have to run it with Spyder because I need scientific packages so when I put this link: https://github.com/llazzaro/lsa_python on Spyder I get this:
[C:\Anaconda2\python.exe: can't open file 'C:\Users\CLIENT\Desktop\lsa_python-master\sanstitre0.py': [Errno 2] No such file or directory]
Maybe you need to set your working directory correctly. It probably looks for the path from the current working directory.
You can change it here:
Little late to answer these questions But still if anyone facing the same issue this answer might help
I was facing the same issue. I even reinstall the anaconda. But it's still doing the same issue. Then I figure out something very silly.
First of all, you have to set your working directory
After that, you have to hit the Run button.
I was pressing ctrl + enter
But after setting the working directory for the first time you have to hit the run button then it will work
Hope it will help.

Categories