Running Python 3 from Light Table - python

I am trying Light Table and learning how to use it. Overall, I like it, but I noticed that the only means of making the watches and inline evaluation work in Python programs uses Python 2.7.8, making it incompatible with some of my code. Is there a way to make it use Python 3 instead?
I looked on Google and GitHub and I couldn't find anything promising.
I am using a Mac with OS X 10.10.2. I have an installation of Python 3.4.0 that runs fine from the Terminal.

I had the same problem with using a syntax that was only valid on Python3.3.
- Go to Settings:User Behaviour
- add the line (find the real path of your python binary):
[:app :lt.plugins.python/python-exe "/usr/bin/python3.4"]
- Save and test in your lighttable
It worked for me :)
Hope it helps

Hit Ctrl + Space to bring up the control pane. Then start typing Set Syntax and select Set Syntax to Python. Start typing your Python then press Ctrl + Shift + Enter to build and run the program.

I got the same problem. It worked for me after saving the file with a .py extension and then typing Cmd+Enter.

Besides changing
Ctrl+Space Settings:User Behaviour
[:app :lt.plugins.python/python-exe "/path_to_your_custom_bin/bin/python3.4"]
There is an issue with Unicode ( 'unicode' is not defined), and I also needed to modify ltmain.py to work with Python3 see here:
https://github.com/eduardflorinescu/lighttable_python3_patch/blob/master/ltmain.py
Make sure you backup the orginal ltmain.py, you can diff the two to see what are the differences and what was changed:

Related

vscode "no refactorings available" for python

Ctrl + alt + R for extension python.python 2020.1.58038 always gives me a "No refactorings available" message.
Probably a configuration issue but I've tried several times to uninstall/reinstall and restart vs code to no avail.
Thought maybe I was missing python-rope but python -m pip install --upgrade rope
Requirement already up-to-date: rope in c:\users\cdoyle\appdata\roaming\python\python37\site-packages (0.16.0)
VS Code Version info :
Version: 1.42.0 (user setup)
Commit: ae08d5460b5a45169385ff3fd44208f431992451
Date: 2020-02-06T10:51:34.058Z
Electron: 6.1.6
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Windows_NT x64 10.0.18362
Also I don't see any open issues
https://github.com/Microsoft/vscode-python/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+refactoring
Not sure what to try next.
Thanks
I'm new to programming Python in VS Code and ran into the same problem. I successfully used the "Rename Symbol" command to rename a function and update all its references. More detail at https://code.visualstudio.com/docs/editor/refactoring . Hope this helps!
I would like to add further:
If you want to change a variable name / function name at one go, you can use "Rename Symbol" in VS Code editor by right clicking that particular name.
If your code has something related to both variable name and function name and you want to apply the change at both places, then you can use "Change all Occurrences".
Example of above-
test = "Hello"
def test_func():
print("World")
print(test)
test_func()
If i want to change variable "test" to "new" and function "test_func" to "new_func", i can use "Change all Occurrences".
But if i want to change only say variable name, then i have too use "Rename symbol".
Visual Studio Code and its Python extension is (at the time of writing this) very limited when it comes to refactoring. Out of the box it provides two refactoring actions: Extract Method and Extract Variable. The reason you're seeing "No refactorings available" is because the currently selected text doesn't match any of these actions. Try selecting a line of text and then press [Ctrl][Shift][R].
Rope support was removed in VSCode in favour of Language Server Protocol integration which is used by their Pylance language server extension. Pylance is now installed automatically with vscode-python extension, and it's actively developed - maybe they will implement more refactorings in the future. If you're looking for more robust refactoring, check out PyCharm refactoring, it is currently much more sophisticated.
For Python 3.10.2 use right-click, Change All Occurrences (CTRL-F2) on VSCode version 1.65.2
I think #Wayne Barrrass-Brown's answer is the best answer available, but just wanted to add something I've found helpful in similar situations.
Double click the variable you want to change, then CTRL+D (which will select the next occurrence of that text) until you've selected all the occurrences you want to change, then type in the new text you want for the selected variable/text.

calling precompiled module from another file

Primarirly I am c++ developer trying to use python for certain tasks for me.
I have made a python module in python 3.6 and got it pre-compiled in windows 7 using the following command
python -m py_compile myfile.py
using information from this link. I get "myfile.pyc" created
Now I want to use this in a python file which is using python 2.7
so, I use information from this and this & write
mod=imp.load_source('myfile.func', 'c:/folder1/folder2/myfile.pyc')
But the above statement gives me exception
[name 'o' is not defined]
Is this because I am using pre-compiled in 3.6 & using in 2.7?
What is that am I missing here
First python 3.6 is not backwards compatible with python 2.7. Secondly its usually better to import the module as normal and let the compiler handle caching library code as compiled byte code. Also the function load_source is meant for loading uncompiled source files, the function you want is load_compiled. Check here
https://docs.python.org/2/library/imp.html
Lastly, if you are looking for performance improvements this will only help reduce compile time, and only on the first compile or when the imported file changes.
What is __pycache__?
This is the complete solution of my problem. ( If you do not want to go through all the comment & discussion & figuring out the solution )
As Mr. Garrigan Stafford aptly pointed out that I am using the wrong API for loading the module.
The API for loading a compiled module is load_compiled & not load_source.
When I started using this API, ran in to the error of magic number: Bad magic number.
This happens because while creating the file, the compiler inserts certain values to basically identify what file is it. ( more info : can be found here.).
In my case, compiled my lib is 3.6 & used in 2.7 which was causing the problem.
To overcome, I basically went back to the original code & compiled my lib in 2.7 & then used it in the client code.
Volla !!!!
All works fine now.
Thanks to stackoverflow community as whole & Mr. Stafford in particular for helping out.

eric6 can't compile in Python form (could not start pyuic5.exe)

I am trying to create a GUI using eric6 for a Python script I coded recently, however when I right click in eric6 on the new *.ui file I create and I try to compile it (choosing 'Compile Form'), the following error is displayed - could not start puyic5.exe:
I have tried the (very few) online solutions but without any luck (for example, checking that in the pyuic5.bat file, the mentioned directory is without any space, and also tried to re-install Qt5). Furthermore, even though both Python and PyQt are correctly installed, pyuic5.exe is missing in the directory specified in the error. Also, everything seems setup ok in the PATH in the system environmental variables.
Versions info:
Python 3.4.5
Qt 5.4.1
PyQt 5.4.1
eric6 17.06
EDIT: if it can help debugging my issue, I would like to add that if I open a command prompt and I invoke pyuic5 mainform.ui -o mainform.py it works without problems. Instead, in eric6, such error message is generated.
Thank you in advance for any precious help and guidance you may offer !
Sincerely,
Paolo
Solved downgrading to an older version of eric6 (precisely to v 17.04.1). Thought it might be useful to share in case somebody encounters the same problem.

How to enable intellisense for python in Visual Studio Code with anaconda3?

I've been using Visual Studio Community for a few months now, but the sluggishness and project-based interface is not to my liking and having seen that Visual Studio Code has a python extension, I decided to try Code again.
There are two problems with Code, that if possible to solve I'd promote it to my main editor.
First is intellisense. I have downloaded the python extension for Code, which promises intellisense. However, outside of the core python packages (like "math") intellisense is not working. I've tried to set up the extra environment variable as described in the link, but that didn't work either.
After this I re-crated an anaconda environment, just in case. Each anaconda environment basically operates as a separate python install and has the modules like "scipy" etc under Lib/site-packages to properly be able to reference them.
As you might guess, intellisense for VS Code still isn't working. Maybe there's a way to refresh its database like for VS Community but I couldn't find it.
My second issue is lack of auto-indentation for python, which wasn't the case when I first installed Code some 6 months ago. The issue was present 2-3 months ago, I hoped it was fixed by now but apparently not. There's nothing new written about it on the Internets either.
How do I get VS Code to work well for me with python?
I have installed python 3.6.5 and Django 2.0.4 on windows 10 OS.
In vs code open command palette (Ctrl+Shift+p).
There select Python:Select Interpreter
Close your vs code and then try. If it still does not work. Try again by changing to:-
Python:Build Workspace symbols and re-open the vs code. That's all i did and got intelligence enabled.
Old question that worth another working answer:
In settings.json, set the value of python.jediEnabled to false (see some more details here).
P.S. You can also try and move back to Jedi (just remove python.jediEnabled or set it to true), and in my case, Intellisense keeps working, though much slower.
This is how I got Python intellisense to start working in VS Code:
open up the Terminal (View menu => Terminal)
type conda init powershell
restart VS Code
After that, Python intellisense started working correctly for me.
On your VS code use the command ctr + shift + P then search for Python: Select Lint and choose your preferred linting tool. This worked for me.
Bro, instead of
import matplotlib.pyplot as plt
Try:
from matplotlib import pyplot as plt
I've tried it in VSCode and it works for the second statement but not the first statement.
This is how I got it to work:
Open command palette (Ctrl + Shift + P).
Type "Python: Build Workspace Symbols" and hit Enter.
Done.

Why python.exe stopped working?

I try to use OpenCV for Python. I have just two lines of the code:
import cv
capture = cv.CreateFileCapture('test.avi')
If I run this code from the command line, Windows creates a window with the following message:
python.exe stopped working
A problem caused the program to stop working correctly.
Windows will close the program and notify you if a solution is available.
What can be the a reason of that?
I would like to add some details. Not sure if they are relevant. In the examples that I found people use cvCreateFileCapture instead of cv.CreateFileCapture. But in this case my program generate a NameError (cvCreateFileCapture is not found).
In general I was able to do a simple stuff with the OpenCV (so, it is installed and it works). For example I was able to change format of an image:
import cv
im = cv.LoadImageM("test.jpg")
print type(im)
cv.SaveImage("test.png", im)
ADDED
"In OpenCV2.2\samples\python" I found many *.py samples. I run some of them and they work fine (I see some animation and so on). The I tried to find a file that contains "CreateFileCapture". I found only one such file (minidemo.py) and I run it. As a result I got the same problem as described above.
Python on opencv has changed, see here make sure you have the latest opencv install - you might also need numpy

Categories

Resources