I understand that you can run a python script from the command line by entering in the file name. What changes do I need to make with a file that has dependencies?
To be more specific, I'm using Pycharm with a specific Anaconda environment for a project. This environment has packages included such as tensorflow and keras. I can run it directly from Pycharm, however when I try to run from the command line, it gives and error saying that
"there is no model named 'tensorflow'"
What can I do to the command line to signal that it should be using a conda environment, let's call it Env1. I've tried activating the environment in the conda command shell and I still get the same problem. How can I address this?
Thanks
In vscode, While running my python script on interactive python window in other conda environment (apart from base environment), I get the following error -
'Timed out waiting to get a heartbeat from kernel process.'
Script works fine in base environment but not in other envrionments. Also, this is specific for python interactive window. It works fine in terminal.
Has anyone faced this issue as well?
According to your description, code works fine in base environment and terminal, while got error in other conda and interactive window. So try to solve the problem with following steps:
Create a new conda environment, reference: python-environments
To use the window with a .py file, select the Run Current File in Python Interactive window command from the Command Palette. More information and details you can reference: python-interactive.
Here you'll get the output. The following is a demo screenshot.
Considering your question is related to python extension, if the above not work, reinstall python extension and try again.
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
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.
I was using python(x,y), which came with Spyder. Yesterday, Spyder crashed I can't figure it out how to fix it. I uninstalled python(x,y) and reinstalled, still the same problem.
If I try to open Spyder I get this message:
Spyder crashed during last session
If Spyder does not start at all and before submitting a bug report, please try to reset setting to defaults by running Spyder with the command line option '--reset:
python spyder --reset
Of course, I tried to do the above, but it doesn't seem like I have Spyder in my path. When I try to put
python spyder --reset
in my command prompt window, I get this error message:
python: can't open file 'spyder': [Errno 2] No such file or directory
I made some attempts of trying to add spyder to path, but they all failed. How should I go about adding Spyder to path?
I am using Windows Vista on a 32 bit system.
My Spyder Crash report looks like this:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\spyderlib\spyder.py", line 1547, in main
mainwindow = run_spyder(app, options)
File "C:\Python27\lib\site-packages\spyderlib\spyder.py", line 1472, in run_spyder
main.setup()
File "C:\Python27\lib\site-packages\spyderlib\spyder.py", line 555, in setup
multithreaded=self.multithreaded)
File "C:\Python27\lib\site-packages\spyderlib\plugins\console.py", line 54, in __init__
light_background=light_background)
File "C:\Python27\lib\site-packages\spyderlib\widgets\internalshell.py", line 101, in __init__
debug, profile)
File "C:\Python27\lib\site-packages\spyderlib\widgets\shell.py", line 698, in __init__
ShellBaseWidget.__init__(self, parent, history_filename, debug, profile)
File "C:\Python27\lib\site-packages\spyderlib\widgets\shell.py", line 61, in __init__
self.history = self.load_history()
File "C:\Python27\lib\site-packages\spyderlib\widgets\shell.py", line 500, in load_history
if rawhistory[1] != self.INITHISTORY[1]:
IndexError: list index out of range
I am terrible with this stuff, so I might be missing something completely obvious or doing something really stupid.
I am wondering if anyone else ran into a similar problem, or can just give suggestions on what to do, and how to do this "reset" thing, or maybe other advice.
Thank You in Advance
python doesn't search spyder in the PATH e.g.:
c:\some\dir> python some_file
Here python tries to read c:\some\dir\some_file file i.e., it looks in the current directory for some_file file.
c:\some\dir> python another_dir\some_file
Here python tries to read c:\some\dir\another_dir\some_file file i.e., it looks in the another_dir directory for some_file file.
c:\some\dir> python C:\path\to\some_file
Here python tries to read C:\path\to\some_file file i.e., it looks in the C:\path\to directory.
If documentation says run: python spyder --reset it assumes that you're in the directory where spyder script lives. It works both from the source checkout scripts directory (if you'd like to run it without installation) and from whatever directory the installation puts scripts in.
Installation process should create spyder or spyder.bat files. If spyder.bat in your PATH then you could run it as:
c:\any\dir> spyder
So instead of python spyder --reset you could try:
c:\any\dir> spyder --reset
The traceback shows that the first executed function is spyderlib.spyder.main(),
source code for the spyder script confirms it, so you can run:
python -c "from spyderlib.spyder import main; main()" --reset
don't worry, it is very easy to reset the spyder. for windows 10 users, you all need to type 'spyder' in 'Cortana' then you can see in apps category something like 'reset spyder setting' just click on that and some black screen will open and your problem will be solved. now you can open your spyder.
I have this problem in windows and it resolved by updating the spyder
pip install -U spyder
I am working with conda virtual environments and if you run
python spyder --reset it it will output the same error message. However, unlike stated above, no need to uninstall anaconda or look for any files.
Just activate your virtual environment as you usually do and write (no need for 'python' in there):
conda activate [name of your virtual env]
spyder --reset
This works for me.
Most of the users' spyder settings are in the user folder .Spyder file name.By deleting it.You will be able to restart the IDE and a new .Spyder directory would be created
For starters in winpython, I too faced this problem of spyder/spyder-reset not starting . And finally this is how it started :
opened command line went to :
D:\manas\mak\crap\WinPython-64bit-3.4.4.2\scripts
typed in spyder.bat
And that opened spyder .
Perhaps the environment variable is stuck at .exe when clicking on the spyder icon and preventing it to load.
Best solution as per my experience: uninstall spyder first, delete all the spyder files under conda > lib > site-packages > ..
1. pip install ipython
2. pip install spyder
3. spyder --reset
I had a similar problem. I had both two installations of Python27---the Ananaconda distribution and the other. Python27 folders appeared before the Anaconda ones in my search path, although Spyder was executed through the Anaconda executable.
It turned out that making the Anaconda distribution folders first in the PYTHONPATH solved the problem.
An easier solution--avoid multiple installations of Python27 if possible.
I tried the method about "python -c "from spyderlib.spyder import main; main()" --reset",but it seems that I don't have the spyderlib.spyder.Then,I solve this problem through install another version of spyder(you can find from anaconda if you use it),you can run:
conda install -c anaconda spyder-app=2.3.8
and it works.
Searched for spyder.bat, per prev answer, and after changing to that directoy - ran the python spyder --reset command.
C:\WinPython-32bit-2.7.3.3\python-2.7.3>cd scripts
C:\WinPython-32bit-2.7.3.3\python-2.7.3\Scripts>python spyder --reset