After 2 weeks, my request to install anaconda at work finally got accepted and after small struggles with windows (coming from mac) I finally got my script working but now I can't seem to execute my script outside of the spyder editor included in anaconda. I want to run my script over Anaconda Prompt but whenever I run the script I get the following error:
Since the error already occurs in the first line I will spare you the rest of the code. But as mentioned before, the script works perfectly fine in spyder but causes an SyntaxError in anaconda prompt. The referenced cmd module is this one: https://docs.python.org/3.4/library/cmd.html
Note: I tried pip installing cmd but couldn't. I am guessing because of my missing admin rights. Instead I just copied the code for the module into a py file into the folder of my project. It works completely fine in spyder.
Related
I've poured through the current answers on this and none have helped. I can't get vscode to detect the virtual env I've created. I'm currently in a state where:
I added the path of the '/my/absolute/path/bin/python3' to the vscode default interpreter path.
As a result the linter is detecting the packages
However when I try to get vscode to execute the script it throws the "ImportError", therefore not recognizing the packages i installed in the virtual env.
Addendum: if i run the script with $python3 myscript.py Everything works fine.
I guess I could just run everything in the command line but it seems like a shame. Anybody got leads on how to fix this?
Thanks already :)
I have just started working on my new pc and just to get a feel for it I wanted first to start working on python files, so I started first by just wanting to run WSL on windows and it installed correctly but when I want to run any python using the run python file on the top right on VS code, this is what gets executed $ C:/Users/jaffe/AppData/Local/Microsoft/WindowsApps/python3.10.exe f:/Projects/hello.py
And this is the error: -bash: C:/Users/jaffe/AppData/Local/Microsoft/WindowsApps/python3.10.exe: No such file or directory
I have no idea what's causing it but when I run the file using 'Shift + Enter' which is: Python: Run Selection/Line in Python Terminal it seems to run the single line correctly but it gives me this error instead:
print("Hello, world")
-bash: syntax error near unexpected token `"Hello, world"'
but when I run it using python3 hello.py, it works perfectly fine?! I'm so lost as to why this is happening and how could I fix it.
Might be relevant: I'm using windows 10, installed python 3.10.2 from windows store, all of that is in VS code and the python code is one line: print("Hello, world") and I changed the permissions of Local/Microsoft/WindowsApps so it's now accessible by all users to view/read/edit/run, made sure that python3.10.exe exists(on the WindowsApps and it works perfectly) and reinstalled it many times, tired python3.9, and tried to install python from the website instead of the windows store and still the same, manually added python to PATH and tried .venv and didn't work. when I launch python3.10.exe outside vs code it seems to run perfectly, I have worked with python before and it used to work fine now I don't know what's wrong.
I have seen other questions of the same problem I'm having here but none of them solve the problem.
No such file or directory C:/Users/...
For wsl, the Windows filesystem is accessible, but it has a different path. It is mounted under the /mnt folder. So you would find your python .exe under /mnt/c/Users/jaffe/AppData/Local/Microsoft/WindowsApps/python3.10.exe. This said, the executable file is meant to work on Windows, and it doesn't really makes sense to use it on Linux when you could run python within your wsl distro.
python3 works perfectly fine
This is because most Linux distributions come with python3 pre-installed, so you can use it already. To see where it is located, you can run the command which python3, or python3 --version to check its version.
If you want to change version, you may consider download it from you package manager, apt.
I also suggest to install python3-pip if you don't have it already to get the pip package manager for python.
In my case when I ran into this.. I discovered pyenv. This allows you to download more than one version of python. You can then go into a specific directory, such as your python project and issue a python local 3.10.0 (for example). Here's a link on how to install it as well as poetry which is a virtual environment manager that is become very popular. You can also create an alias for python that works off of this. I add this command to my alias file and source it from my .bashrc. alias python='pyenv exec python3'
Okay, weird thing. This works perfectly fine in Linux, but I cannot get it to work in Windows. Problem might be that I'm not working in Windows a lot these days...
I've got a Python script that I want to run from a C++/Qt program. So I installed Anaconda and within the "Anaconda Prompt" I installed the package containing the script via pip. I've got the full path to the Python script (defined as an entry_point in the packages's setup.py, so it's actually an exe file) and try to start it like this:
proc = new QProcess(this);
connect(proc, &QProcess::readyReadStandardError, this, &MainWindow::receivedText);
connect(proc, &QProcess::readyReadStandardOutput, this, &MainWindow::receivedText);
proc->start(python_script, arguments);
Where python_script and arguments are the full path to the python script and its arguments. When I run this from the "Anaconda Prompt", it works fine, but from my Qt program I get a "NumPy not installed" error, although it's definitely installed. Could it be that I have to run "conda activate" somehow first? Sorry, I'm not really familiar with Anaconda, only using it in Windows... How would I do that?
Thanks!
can you open a dos prompt shell from your code? If so, you can get anaconda to start within that shell and then run your conda activate commands, etc.
Try this command to see if this is an option, you may need to change the paths from miniconda3 depending on what anaconda app you are using:
%windir%\System32\cmd.exe "/K" C:\Users\user\miniconda3\Scripts\activate.bat C:\Users\user\miniconda3
Found a method that works: instead of calling the script directly as "script.exe arguments", I can run it through the Python interpreter as "python.exe script.exe arguments", which seems to work nicely.
I keep having the same issue when I switch servers, so posting a solution which always works for me:
conda install -c conda-forge implicit
I wrote a program that use pyperclip module and it would work from Pycharm and python IDLE, would work as well if starting from Powershell but if I try to start the program from WIN+R, when launched, the program returns an error saying that pyperclip module is not installed. The same problem appears when I run it from the Anaconda Powershell Prompt.
PLEASE NOTICE:
The program was working perfectly before I installed Anaconda and Jupyterlab.
The error occurs when I run the program from the cmd using WIN+R AND when I run it from the Anaconda Command Prompt but it's fine when run from IDLE, Powershell, Pycharm.
I always used python 3 and only yesterday I installed Anaconda.
Thanks for the help!
I just spent couple of hours trying to solve exactly the same problem. What I found out is that, as couple of members have already pointed out, the main problem is the mismatch between the version of the python that runs in cmd and the versions of the python used in scripts/batch files.
The first line in the code, known as "shebang", in .py file indicates the version of the python that the script should use when it is executed. So, it must match the version run by default with cmd (or when executed with win+R). In my case, I also have a batch file (.bat) that calls specified version of the python, which should be the same version used with .py file.
The problem was that both of my files (.py and .bat) were calling python 3.8 while the cmd is running version 3.7. Initially, I used shebang #! python3 in my .py file, and command #py path/to/python/file.py %* (and I also tried #py.exe path/to/python/file.py %*) in my .bat file, and that did not work.
To solve the problem, I updated these two files to link to python version 3.7 with following:
changed shebang in .py file to #! python
changed command in .bat file to #python path/to/python/file.py %*
With these changes the system runs the program with win+R.
whew, taking course on python and instructor had py.exe instead of python.exe in .bat call. despite trying all of the other installation methods others have mentioned, just changing this to python.exe did that trick.
On a windows 7 (64-bits) machine I installed python 2.7.
Then installed pyinstaller, pypiwin32, pywin32-ctypes in this order, by running "pip install pyinstaller" etc in command prompt. Each time some files were downloaded and a success message was shown.
Then I restarted my computer.
After doing above, I ran "pyinstaller" in command prompt (just this, didnt mention the python code file I wrote) to test the installions.
I get a detailed error message, whose last line is shown below (the whole error message is I think too cumbersome and unnecessary to be shown here):
C:\Python27>pyinstaller
ImportError: No module named dis3
Same error came when I ran the command from c:\python27, c:\python27\scripts.
Same error also came when I ran the command mentioning my python code file from above directories and also from the directory where my python code file is.
The other questions here related to import errors mentioning some modules when running pyinstaller command are about programming errors inside users' codes such as not mentioning a module in import statement because of hidden dependency etc. I think my error is related to installation (because as stated above, even when I dont pass my code file to the command same error comes).
Is the problem with installion or with my code?
If the problem is with installion, what do I need to install or uninstall, and in which order?
If the problem is in my code then what do I have to import?
dis3 is not a dependency of pyinstaller. You must install it via pip install dis3.
This is needed only if you're trying to "pyinstall" a bunch of code written in python 2.7