I'm using WSL2 with a Ubuntu distro with a conda package manager. I can read and edit files on Windows ( accessed via /mnt/c) using the Visual Studio Code GUI (launched by code . in the WSL Ubuntu terminal).
I have following script where I'm trying to remove spaces from the name of all pdf files:
import os
fldr = '/mnt/c/Documents and Settings/Lenovo/Desktop/'
for f in os.listdir(fldr):
if 'pdf' in f:
print(f)
os.rename(fldr+f, fldr+f.replace(' ','_'))
print(f.replace(' ','_'))
If I run the script via the debugger (F5) I get a permission error [Errno 13]
If I use the terminal created by debugger to manually rename using Python code, I don't get the permission error.
I am pretty sure there is a difference between the user that runs the debugger (which runs in your windows) and the user that is running inside WSL.
try running the following command to set the username the same as the windows one:
wsl --user <your username>
Related
I have to run a shell script on a Centos Linux machine that calls a python file. Inside the python file, there is the following code snippet:
from lib.rclone import Rclone
rclone = Rclone()
if shutil.which("rclone") == None:
print("Rclone executable is missing, install it")`
The problem is that I am not supposed to install any code (including rclone) on the machine. Therefore, whenever I call the shell script, it ends up with the error message. I don't know how can I successfully run it?
The program you are running requires rclone. Since you cannot install it, you cannot run it. Simple as that.
You can try to release the script as a .exe file.
By using pyinstaller (https://pyinstaller.org/) you don't have to install any libs or py package on the target machine, you can even choose to release it as a single executable.
I am currently using VS Code on a server (through SSH). Everything works fine, and I installed Python packages and work with Python notebooks.
Now, I want to login to the server (not a problem) and run the Python code I created on VSCode, rather than executing it remotely.
My main issue is that I am not sure how to activate the Python environment (if there is one) that VSCode server's run so that the code can execute.
Is that possible?
I see I have a .vscode directory in my home directory, and there are package installation there.
After connecting vscode remotely, you can use it as a regular vscode, which is no different from running Python files locally:
install python
install pylance extension
choose correct interpreter
edit your code and run the python file.
Context: Running python in VSCode on Windows
Default Terminal is Bash (via WSL)
Using WSL - Debian
Python 3 installed on Windows, not on WSL
I want Bash to call my Windows Python Executable when I run my python files. I am only using WSL so I can replace cmd/powershell with bash. I do not want to install anything on WSL, I want to use existing programs on Windows (in this case Python).
However when I try to run my Python file (Clicking 'play' button) I get the error:
-bash: C:/Users/Connor/AppData/Local/Programs/Python/Python310/python.exe: No such file or directory
I believe this can be solved by replacing C: with \mnt\c
How can I achieve this?
I had a same problem as yours. I solved this by following steps.
Open the VSCode
On your left-down side, you can see the the icon that I pointed enter image description here (the name in here is "Open a Remote Window")
Next you can see above the "Reopen Folder in WSL" enter image description here and clicked
Then you can run python with wsl and no more directory errors
I'm having some issues running Python 3, which I installed with Anaconda, through Git Bash. I'm able to access the interactive environment by entering python but whenever I enter:
python webscraper.py
I get this:
C:/Users/[My username]/anaconda3/python.exe: can't open file 'webscraper.py': [Errno 2]
No such file or directory
The Python file is in the same directory I'm currently working in when I'm getting these errors. The path to my version of Python through Anaconda also looks like it's correct. I was previously able to test scripts in Bash but had to reinstall it to solve some other issue.
First, check if you are using the right python:
which python # in your git bash session
Then test it with the full absolute pathname of the file, as described here:
python /full/path/to/webscrapper.py
I've prepared a module that's ready to be uploaded to PyPI, the folder 'nester' has all the necessary components. Equipped with the build, dist, MANIFEST, and the two python files (setup.py and nester.py). Whenever I go to admin PowerShell I try running the final command to download it onto my local python file.
python.exe setup.py install
it spits back out 'permission denied', am I putting in the wrong command? the textbook I'm working from is working on terminal while I'm on Windows. The aforementioned textbook inputs
Sudo python3 setup.py install
and it seems to work perfectly for him 😒
here's what happens every time I try to run it
This likely happens, as the installer is trying to write into C:\Program Files directory. Ordinary user accounts do not have permission to do so, as the error Access Denied says.
/In *nix systems, sudo is used to act as root, and root can do anything. Thus permissions aren't an issue in the book sample.)
To illustrate your Windows case, see the image below. In the first case, ordinary user is trying to create test.txt into C:\Program Files. It fails, as expected. The second case does the same, but this time Command Prompt is started with administrative privileges.
As for a fix, you need to run the command in elevated command prompt. The prompt should have window title Administrator: Command Prompt, not C:\Windows\system32\cmd.exe.