Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use Spyder to open python scripts (.py files) from the terminal or the file explorer #466

Closed
spyder-bot opened this issue Feb 16, 2015 · 65 comments

Comments

@spyder-bot
Copy link
Collaborator

From ccordoba12 on 2010-11-24T19:32:22Z

I would like to write in a terminal

spyder foo.py

to open any python script directly with spyder. If you could do this, you could also associate spyder to open .py files with your file manager of preference (e.g. dophin or nautilus in linux).

In my humble opinion, this would be a great time saver and an important usability improvement. Right now you have to open spyder and look for the file you want to work on, which sometimes can be cumbersome.

Thanks,
Carlos

Original issue: http://code.google.com/p/spyderlib/issues/detail?id=466

@spyder-bot
Copy link
Collaborator Author

From DavidAnt...@gmail.com on 2010-11-24T17:44:56Z

An existing feature which may solve your problem is that you can drag and drop files onto the spyder editor. This works for me under windows, I guess it should also work on linux.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2010-11-27T10:13:19Z

Thanks for your suggestion David, but I thinks it's not good enough. Instead of just double click on a py file and open it, right now you have to open spyder first and drag and drop it, which as I said it's kind of awkward.

I'll try to implement this feature during my winter break, hope to make it for 2.1.

Pierre, do you have any suggestions about where to start to look?

@spyder-bot
Copy link
Collaborator Author

From miniw...@gmail.com on 2010-11-29T03:06:43Z

This probably can be donne with argparse module : https://code.google.com/p/argparse/ (before 2.7) http://docs.python.org/dev/library/argparse.html

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2010-12-01T10:45:20Z

Owner: ccordoba12
Labels: -Type-Defect Type-Enhancement Milestone-Release2.1

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2010-12-01T10:51:51Z

In current implementation, the command line options are parsed here in spyder.py: https://code.google.com/p/spyderlib/source/browse/spyderlib/spyder.py#1428 (the function 'get_options' uses the standard library module 'optparse')

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2011-01-07T04:46:57Z

issue #509 has been merged into this issue.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-03-06T15:02:41Z

Hi,

I've added this functionality to the clone named ccordoba12-open-file. It's a simple change, but I wanted to put it in a separate branch, because now that this is in place there are two further things that could need more development:

  1. Do we want to have a single instance of spyder now? Well, I for sure would want to open all my files on just one spyder instance.
  2. Even if 1. is not accepted, new files should appear at the end of the tab bar on the editor after opening them. This is the expected behavior from browsers and other IDEs. (Somehow related to issue Editor: drag n' drop (movable) tabs #564 I think)

Please clone the repo and check if it's working fine on Windows and Mac. I've only tested on Linux.

Cheers,
Carlos

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-03-06T15:40:34Z

There is another thing I forgot the mention:

  1. Should we enforce a working directory change when opening a file in this new way? I think we should, to respect the options in Preferences > Global working directory > Change to file base directory.

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2011-03-09T13:21:42Z

  1. I'd say yes, we want a single instance as Spyder is designed in this way
  2. Not necessarily. I think that these are two separate matters: the behavior when opening scripts from terminal should be the same as when opening these scripts from Spyder's main window, for consistency's sake (now this does not prevent us from changing the way files are opened and distributed over the editor's tab, but this is really an independent matter)
  3. For the same reason as 2., I think again that the behavior should be the same as opening the file from the main window: so if the Global Working Directory is supposed to be changed accordingly in this situation, so be it

If files are opened with spyderlib.plugins.Editor.load, points 2. and 3. will be automatically solved.

I'll take a look at it on Windows - I'm on Linux for now (I can't test it from MacOS...).

@spyder-bot
Copy link
Collaborator Author

From mortba...@gmail.com on 2011-05-11T22:15:28Z

  1. i would like to thank you for this great IDE, i'm a student who enjoys spyder.
  2. i really like this feature to directly open files with spyder from commandline. The process of opening behaves as i expected, but maybe it would be possible to do it without the additional -o option because that would be the behavior known from other software.

Another enhancement would be to open a file per right click and say open with spyder.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-05-14T15:04:35Z

Thanks for your encouragement!!

I'll try to solve this issue for 2.1 (the next release), although it has proven to be a bit beyond my programming skills. Let's see what we can do about it.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-10-29T06:26:07Z

I didn't make it for 2.1. Sorry. There were a lot of other things to take care of, but I work on it for 2.2.

Labels: -Milestone-Release2.1 Milestone-Release2.2

@spyder-bot
Copy link
Collaborator Author

From billhugh...@gmail.com on 2012-02-17T08:33:01Z

I've been spreading the word about Spyder to all of my customers who are mainly Windows users. Great IDE but +1 for Right Click, open with spyder. This is kinda critical for us and allows use of the IDE with other .net applications we use.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-02-17T12:28:35Z

Hi Bill, it's definitely in my radar for 2.2 (hopefully a summer edition). I'm glad you like Spyder.

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2012-03-11T06:13:17Z

The "Open with Spyder" context menu entry feature is going to be platform-dependent, so let's open an issue for Windows to start with -- see issue #971 .

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2012-03-18T13:45:45Z

Labels: -Milestone-Release2.2 Milestone-v2.2

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2012-03-18T13:56:53Z

Labels: -Milestone-v2.2 MS-v2.2

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2012-03-18T14:15:40Z

Labels: -Type-Enhancement Type-Enh

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2012-04-21T06:59:52Z

issue #999 has been merged into this issue.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-07-04T07:51:38Z

Blocking: spyderlib:1089

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-07-08T08:51:09Z

issue #1112 has been merged into this issue.

@spyder-bot
Copy link
Collaborator Author

From techtonik@gmail.com on 2012-07-09T01:04:38Z

Blocking: spyderlib:1112

@spyder-bot
Copy link
Collaborator Author

From c.ed.m...@gmail.com on 2012-08-04T21:45:16Z

Spyder is a fantastic IDE, and I really appreciate everyone's work.

As for constructive comments, I think, as mentioned in comment 10, that the opening should be done without the -o argument. This is simple because argparse supports collecting the remaining "free-floating" arguments which could just be treated as a list of files.

On that note, opening several files is important. i.e.

spyder a.py b.py c.py

should open all three.

If possible, it would be nice to support

spyder *.py

to open all python files in the working directory. This could be implemented fairly simply (might require manually checking for '*.py' in the file argument and then handling it accordingly - use some sort of glob function to collect the files)

Thanks for all your hard work!

@spyder-bot
Copy link
Collaborator Author

From c.ed.m...@gmail.com on 2012-08-05T20:17:28Z

Hi All,

I don't exactly know how the project is structured or how to contribute, but I've implemented the features I described above in my clone: https://code.google.com/r/cedmead-command-line-open/ It's a pretty simple modification of the features ccordoba12 implemented in his clone.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-08-05T20:30:06Z

Hey man, thanks a lot for taking the time to contribute code to solve this feature!

During last month I implemented this feature too, with the addition of opening files in an existing instance. Unfortunately, I haven't had time to test it on Windows, just on Linux, but I hope to push it soon.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-03-16T09:19:20Z

Pierre confirmed to me that this is working for him.

Now it's up to him to add context menu integration for Windows, as described by Jed in comment #40, and which will solve issue #971 .

Status: Fixed

@spyder-bot
Copy link
Collaborator Author

From peter.sc...@gmail.com on 2013-04-21T18:08:17Z

Hello,

also thanks from my side for the great Spyder IDE. I use it under Ubuntu Precise Pangolin atm.

I have a problem with the context menu support. I was able to get Spyder into the context menu, but when I try to open a file with it, Spyder starts but with the last session, instead of opening the intended file.

How can I fix this?

Best regards
Gondo

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-04-21T18:24:53Z

What Spyder version are you using?

@spyder-bot
Copy link
Collaborator Author

From peter.sc...@gmail.com on 2013-04-24T06:00:25Z

Sry, forgot to add...

Originally, I used the version in the Ubuntu repository but I switched to the debian package to fix this issue (which didn't work). So, currently I've got Spyder 2.1.10.

Thx in advance for your help!

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-04-24T09:03:24Z

I thought so. This feature is not present in version 2.1 but in (the about to be released) 2.2, so that's why is not working for you.

I think there is a debian package in testing, or you can use our PPA: https://launchpad.net/~pythonxy/+archive/pythonxy-devel

@spyder-bot
Copy link
Collaborator Author

From peter.sc...@gmail.com on 2013-04-24T15:17:19Z

Works like a charm! Thx for your immediate support and please keep on going with this project!

Best regards
Gondo

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-04-24T15:31:25Z

Glad you like it!

@spyder-bot
Copy link
Collaborator Author

From Zsolt....@gmail.com on 2013-05-29T20:42:11Z

I would like to say thanks that this got implemented and is working perfectly on Windows.

However there is a bug:

  1. As it is now, spyder.bat calls Spyder from an external command line windows, which keeps being open as long as Spyder is open!
  2. Once the user closes Spyder, the command line window terminates with an exception.

A super easy fix is to:

  1. Use pythonw.exe instead of python.exe
  2. You need to call "start" as well.

So the correct version is:
"start %~f0....\pythonw.exe %PYFILE% %*"

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-05-30T10:25:09Z

I guess you are trying to assign Spyder directly to open python files by selecting its .bat script.

That's not how we planned things, because on Windows .py files are meant to be opened with the Python interpreter. Our solution is to install an "Open with" entry that can be accessed through your context menu.

But to get that entry you need to use our Windows installers because they are not installed when one uses pip or easy_install

@spyder-bot
Copy link
Collaborator Author

From Zsolt....@gmail.com on 2013-05-30T10:42:15Z

No, I'm using Total Commander and I'd like to associate it's Alt + F3 editor to open .py files by Spyder. Everything works perfectly, except for the black command line being visible. This is not related to Total Commander or anything, it would happen if I'd call the bat file from command line as well.

It works perfectly, it just needs the last line to be changed to
"start %~f0....\pythonw.exe %PYFILE% %*"
as explained above.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-05-30T10:56:41Z

Ok, I understand, but I think it would easier to just use:

"start /b python.exe %PYFILE% %*"

However, I'm not a Windows expert and so I defer the decision to Jed or Pierre

@spyder-bot
Copy link
Collaborator Author

From Zsolt....@gmail.com on 2013-05-30T11:47:11Z

The "%~f0...." has been there I believe because not everyone adds python to the PATH.

The pythonw.exe is needed over python.exe because the python.exe creates the stupid command window and waits for the process to terminate before closing. http://stackoverflow.com/questions/9705982/pythonw-exe-or-python-exe /B - we don't want to wait for the process here, so we shouldn't use /B but it works for some reason both with and without /B. I don't know which is the better one.

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2013-05-30T12:17:12Z

Actually, there is a specific reason for not using pythonw.exe. See issue #1260 and the accompanying discussion on the mailing list.

The Windows console should disappear after launch if you have installed pywin32 extensions: http://sourceforge.net/projects/pywin32/ The ...win32 name is unfortunate now because they actually work for x64, too. Just have to download the right build for your particular combination of OS and Python: http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-05-30T13:17:02Z

Jed, does the window close too even if you start Spyder by double clicking its bat file? I thought that worked only when you run it through bootstrap.py.

@spyder-bot
Copy link
Collaborator Author

From Zsolt....@gmail.com on 2013-05-30T13:29:19Z

For me, the only way to stop the window appearing is to start with pythonw. I use the Anaconda distribution, which bundles Spyder by default. Is it possible that this doesn't bundle pywin32? How can I test? 'import pywin32'?

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2013-05-30T13:55:30Z

Yes, the console will go away even when double clicking the .bat file. Even more, if you open a command window, cd to the spyder.bat directory, and launch the .bat from the command line the command window will disappear.

Anaconda does not ship with pywin32: http://docs.continuum.io/anaconda/pkgs.html To test from the command line, try this:

import win32con

If that fails, then pywin32 is not installed.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-05-30T13:58:52Z

Yes, I was reading its supplied packages and couldn't find pywin32 (but I thought it wasn't there because its a scientific library per se).

Then I think we should talk with Continuum guys to try to convince them to ship Anaconda with it.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-06-07T09:13:52Z

issue #1434 has been merged into this issue.

@r0cketdyne
Copy link

Is there a working implementation at this yet? UAH student body needs to be able to open files at the terminal emulator within python instead of dragging and dropping.

for example... spyder rando.py

@ccordoba12
Copy link
Member

for example... spyder rando.py

@r0cketdyne, that should be working. I mean, we have tests for it and they are passing right now.

If that's not the case for you, please open a new issue and don't forget to fill our required information. Or better yet, open an issue directly from Spyder (by going to the menu entry Help > Report issue) because it'll grab that info from your own installation.

@r0cketdyne
Copy link

Screen Shot 2024-02-22 at 8 53 15 PM

@r0cketdyne
Copy link

for example... spyder rando.py

@r0cketdyne, that should be working. I mean, we have tests for it and they are passing right now.

If that's not the case for you, please open a new issue and don't forget to fill our required information. Or better yet, open an issue directly from Spyder (by going to the menu entry Help > Report issue) because it'll grab that info from your own installation.

I'll proceed to open with a new issue. Doing so internally might not be the most streamlined way to deal with this given the nature of the error I'm getting here: perhaps I should be using bash? I'll investigate and try to troubleshoot, or open a PR.

@ccordoba12
Copy link
Member

Screen Shot 2024-02-22 at 8 53 15 PM

This could mean several things depending on how installed Spyder:

  • If you use our stand-alone installer for Mac (in case you're using that OS), the spyder command is not available in the command line.
  • If you use Anaconda, you need to activate your environment before running spyder foo.py (which seems you didn't do).
  • If you're using a virtualenv, you also need to activate it before being able to use spyder foo.py.

@robin48gx
Copy link

robin48gx commented Aug 23, 2024

I just brew installed spyder on my MAC M2. It would not even allow me to select a .py file in the browser. I cut&pasted the python I was working on in Linux yesterday into it and found the environment very useful. When I went to save some small changes it wanted to save it in a .R file ????

The code I have is in git and works in linux. I do not want to start altering file name (that may cause bother on linux as well)

Is the default spyder5 configured for the R language or is broken in some way ?

update: I tried again after re-installing.
I just dragged and dropped my python file into spyder. It had the right .py file name. I made a minor change. The save ICON did not activate. Its almost like it does not recognise .py as a valid python file!
OK I am going back to thonny for now.
Pity I quite liked the way it debugged/general IDE. But as configured or this version, simply wont save changes

@dalthviz
Copy link
Member

Hi @robin48gx I would say that the problem you are experiencing could be related with #22248 A fix for that will be available as part of Spyder 5.5.6

Let us know if the info above helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants