Can I run a Kivy program from within Pyscripter? - debugging

I've entered this code in Pyscripter:
import kivy
kivy.require('1.7.2')
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text='Hello Kivy')
MyApp().run()
I then press the Run button (the green triangle).
I get the following error:
Import error: No module named kivy
What can I do to make this work?
P.S. I know I can leave Pyscripter and use kivy.bat,
but I would like to use the debugging capabilities within Pyscripter.

I've had the same trouble and I solved it out using a pyscripter's option in the 'Tools' menu called 'Edit Startup scripts' which's name says it all.
Everything you write there should be executed whenever pyscripter starts a python interpreter so it can be used among other things to do the same as 'kivy.bat' but inside pyscripter, I wrote the following startup script basing on info from here How to develop and run kivy apps on PyDev and it works fine for me.
# This startup script makes it possible to Pyscripter to work with the kivy package
import sys
import os
kivy_path = 'C:/kivy'
relative_modules_paths = ['/kivy',
'/Python/',
'/Python/Lib/',
'/Python/Lib/Site-packages/',]
# tells the interpreter to look for python modules in the kivy modules' paths
for relative_path in relative_modules_paths:
sys.path.append( kivy_path+relative_path )
# sets some environment variables needed by kivy. Not permanent.
os.environ['GST_PLUGIN_PATH'] = kivy_path+'/gstreamer/lib/gstreamer-0.10'
os.environ['GST_REGISTRY'] = kivy_path+'gstreamer/registry.bin'
kivy_environ_paths = '{kp};{kp}/Python;{kp}/gstreamer/bin;{kp}/MinGW/bin;'
kivy_environ_paths = kivy_environ_paths.format( kp=kivy_path )
os.environ['PATH'] = kivy_environ_paths
# theorecally your environment variables won't be affected outside the
# interpreter. You can still backup your environment variables if you
# don't feel confident
Just change the kivy_path variable in the script so it fixes with the kivy package's path (folder containing kivy.bat) on your computer and you should be able to run your kivy apps just like when you open them with kiby.bat

I think this is probably because kivy.bat really sets up and uses a second python distribution that has kivy installed. However, pyscripter is using your normal system installation, which does not have the kivy module installed.
You can probably tell pyscripter to use the kivy interpreter with the right environment set up. I don't know how exactly (I haven't ever tried on windows), but for instance this previous question is similar but about pycharm rather than pyscripter. I have pasted the answer below, some of it relates specifically to pycharm but something similar will probably work for pyscripter.
Install and open PyCharm
If you already had it installed and have a project open, click File -> Settings (Ctrl + Alt + S). (If not, create a new project, and
click the '...' next to interpreter, and skip step 2)
Under Project Settings, click Project Interpreter -> Python Interpreters
Click the little green + and select local (You can also set up an interpreter to your installed python from this list)
Point it to ..\Kivy\Python\python.exe and click ok (Mine's path was c:\Program files (x86)\Kivy\Python\python.exe since that is where
I unzipped the kivy zip file to)
I have also attached a settings.jar file here
https://groups.google.com/forum/#!topic/kivy-users/xTpib2C8r_A. This
is the kv language definition. Its not complete, but it helps a lot.
Click File->Import-> Select the settings.jar file. Only FileTypes will
be ticked. import this and you will have "kv language file" definition
under File->Settings-IDE Settings->File Types
Open a kv file to see the differentiation in colours, as well as
autocomplete Widgets are type 1 Properties are type 2 all events
(on_something) are type 3 type 4 is just self and root.
-- That is all for PyCharm, the rest is Windows 7 specific things. -- 1. open a command prompt and browse to your ..\Kivy\Python\lib folder 2. type mklink /D kivy "..\Kivy\kivy\kivy" (Mines line was mklink /D kivy "c:\Program files (x86)\Kivy\kivy\kivy") This will set up a
symlink so that your all your kivy python files are read and their
definitions are included, in order to get autocomplete
Now we need to set up the environment variables. You could do this per
project inside PyCharm, but might as well do it in windows, so you
only need to select the python interpreter each time Click start and
type envir Select the second one. (System variables) ( You could also
get here with Win+PauseBreak-> Click Advanced system settings) Click
Environment variables
Now add these (Once again, just point to wherever you have your kivy
folder. You can also find all these in the kivy.bat file, just find
and replace the variables with your path)
GST_PLUGIN_PATH c:\Program Files
(x86)\Kivy\gstreamer\lib\gstreamer-0.10
GST_REGISTRY c:\Program Files (x86)\Kivy\gstreamer\registry.bin
PATH c:\Program Files (x86)\Kivy;c:\Program Files
(x86)\Kivy\Python;c:\Program Files (x86)\Kivy\gstreamer\bin;c:\Program
Files (x86)\Kivy\MinGW\bin;c:\Program Files (x86)\Kivy;c:\Program
Files (x86)\Kivy\Python;c:\Program Files
(x86)\Kivy\gstreamer\bin;c:\Program Files (x86)\Kivy\kivy;%PATH%
Restart your machine. (For the environment variables to load)
Now when you open your kivy project, just select the Kivy interpreter
you set up earlier, and bobs your uncle.
You can also try to install kivy in your existing python installation. The kivy website has instructions for this here. I haven't tried this, and there may be some tricky bits.

Related

Install adt Package [duplicate]

In PyCharm, I've added the Python environment /usr/bin/python. However,
from gnuradio import gr
fails as an undefined reference. However, it works fine in the Python interpreter from the command line.
GNURadio works fine with python outside of Pycharm. Everything is installed and configured how I want it.
Gnuradio is located at /usr/local/lib/python2.7/site-packages/gnuradio
Also:
PYTHONPATH=/usr/local/lib/python2.7/site-packages:/usr/local/lib/python2.7/site-packages/gnuradio
Adding a Path
Go into File → Settings → Project Settings → Project Interpreter.
Then press configure interpreter, and navigate to the "Paths" tab.
Press the + button in the Paths area. You can put the path to the module you'd like it to recognize.
But I don't know the path..
Open the python interpreter where you can import the module.
>> import gnuradio
>> gnuradio.__file__
"path/to/gnuradio"
Most commonly you'll have a folder structure like this:
foobarbaz/
gnuradio/
__init__.py
other_file.py
You want to add foobarbaz to the path here.
You should never need to modify the path directly, either through environment variables or sys.path. Whether you use the os (ex. apt-get), or pip in a virtualenv, packages will be installed to a location already on the path.
In your example, GNU Radio is installed to the system Python 2's standard site-packages location, which is already in the path. Pointing PyCharm at the correct interpreter is enough; if it isn't there is something else wrong that isn't apparent. It may be that /usr/bin/python does not point to the same interpreter that GNU Radio was installed in; try pointing specifically at the python2.7 binary. Or, PyCharm used to be somewhat bad at detecting packages; File > Invalidate Caches > Invalidate and Restart would tell it to rescan.
This answer will cover how you should set up a project environment, install packages in different scenarios, and configure PyCharm. I refer multiple times to the Python Packaging User Guide, written by the same group that maintains the official Python packaging tools.
The correct way to develop a Python application is with a virtualenv. Packages and version are installed without affecting the system or other projects. PyCharm has a built-in interface to create a virtualenv and install packages. Or you can create it from the command line and then point PyCharm at it.
$ cd MyProject
$ python2 -m virtualenv env
$ . env/bin/activate
$ pip install -U pip setuptools # get the latest versions
$ pip install flask # install other packages
In your PyCharm project, go to File > Settings > Project > Project Interpreter. If you used virtualenvwrapper or PyCharm to create the env, then it should show up in the menu. If not, click the gear, choose Add Local, and locate the Python binary in the env. PyCharm will display all the packages in the selected env.
In some cases, such as with GNU Radio, there is no package to install with pip, the package was installed system-wide when you install the rest of GNU Radio (ex. apt-get install gnuradio). In this case, you should still use a virtualenv, but you'll need to make it aware of this system package.
$ python2 -m virtualenv --system-site-packages env
Unfortunately it looks a little messy, because all system packages will now appear in your env, but they are just links, you can still safely install or upgrade packages without affecting the system.
In some cases, you will have multiple local packages you're developing, and will want one project to use the other package. In this case you might think you have to add the local package to the other project's path, but this is not the case. You should install your package in development mode. All this requires is adding a setup.py file to your package, which will be required anyway to properly distribute and deploy the package later.
Minimal setup.py for your first project:
from setuptools import setup, find_packages
setup(
name='mypackage',
version='0.1',
packages=find_packages(),
)
Then install it in your second project's env:
$ pip install -e /path/to/first/project
For me, it was just a matter of marking the directory as a source root.
Add path in PyCharm 2017
File -> Settings (or Ctrl+Alt+S) -> Project -> Project Interpreter
Show all
Select bottom icon on the right side
Click on the plus button to add new path to your module
My version is PyCharm Professional edition 3.4, and the Adding a Path part is different.
You can go to "Preferences" --> "Project Interpreter". Choose the tool button at the right top corner.
Then choose "More..." --> "Show path for the selected interpreter" --> "Add". Then you can add a path.
DON'T change the interpreter path.
Change the project structure instead:
File -> Settings -> Project -> Project structure -> Add content root
In PyCharm 2020.1 CE and Professional, you can add a path to your project's Python interpreter by doing the following:
1) Click the interpreter in the bottom right corner of the project and select 'Interpreter Settings'
2) Click the settings button to the right of the interpreter name and select 'Show All':
3) Make sure your project's interpreter is selected and click the fifth button in the bottom toolbar, 'show paths for the selected interpreter':
4) Click the '+' button in the bottom toolbar and add a path to the folder containing your module:
For PyCharm Community Edition 2016.3.2 it is:
"Project Interpreter" -> Top right settings icon -> "More".
Then on the right side there should be a packages icon. When hovering over it it should say "Show paths for selected interpreter". Click it.
Then click the "Add" button or press "alt+insert" to add a new path.
As quick n dirty fix, this worked for me:
Adding this 2 lines before the problematic import:
import sys
sys.path.append('C:\\Python27\\Lib\site-packages')
On Project Explorer, you can right click on the folder where the module is contained and set as 'Source'.
It will be parsed in the Index for code completion as well as other items.
I'm new to PyCharm (using 2018.3.4 CE) and Python so I rotely tried to follow each of the above suggestions to access the PIL (Pillow) package which I knew was in system-site-packages. None worked. I was about to give up for the night when I happened to notice the venv/pyvenv.cfg file under my project in the Project Explorer window. I found the line "include-system-site-packages = false" in that file and so I changed it to "true". Problem solved.
In my PyCharm 2019.3, select the project, then File ---> Settings, then Project: YourProjectName, in 'Project Interpreter', click the interpreter or settings, ---> Show all... ---> Select the current interpreter ---> Show paths for the selected interpreter ---> then click 'Add' to add your library, in my case, it is a wheel package
For me there is also another issue. If you try to add a folder that in the past had a .idea folder, but your current project has it's own .idea folder your pycharm might get confused for some reason -- even if you have the right python/conda env. For me deleting the .idea folder of the other project fixed the confusion that it could find the obviously correctly installed pkgs. Then it was it was able to find them in the pycharm editor GUI snf stopped underlyinging them in red.
Download anaconda
https://anaconda.org/
once done installing anaconda...
Go into Settings -> Project Settings -> Project Interpreter.
Then navigate to the "Paths" tab and search for /anaconda/bin/python
click apply

Don't get GraphViz and phpDocumentor to work

I'm trying to create a php documentation on my local XAMPP host (on Windows 7) with phpDocumentor.phar (v2.). It gives me (after parsing all the files) this error:
Unable to find the dot command of the GraphViz package. Is GraphViz correctly installed and present in your path?
I searched a lot, but nothing helps. What does 'path' means? If I open a command box at any location I can start the dot.exe (which gives me no output but waiting prompt). In my environment path variable the bin folders is added. GraphViz is installed correct in Program Files and runs standalone.
What could I do or check?
In order to get GraphViz running properly with a Windows based phpdoc installation, just put the GraphViz program directory (c:\some\path\graphviz\release\bin) to the Windows Path system variable.
In order to do this, follow these steps (Win7, please provide your OS version if this doesn't apply to your situation):
From the desktop, right-click My Computer and click Properties.
In the System Properties window, click on the Advanced tab.
In the Advanced section, click the Environment Variables button.
In the Environment Variables window, highlight the Path variable in the Systems Variable section and click the Edit button.
Different directories are separated with a semicolon:
C:\Program Files;C:\Winnt;C:\Winnt\System32
It will most likely look a bit different in your enviroment, so please just take this for an example. Just add the GraphViz Path at the end like this:
C:\Program Files;C:\Winnt;C:\Winnt\System32;C:\somefolder\graphviz\release\bin
I'm not too sure if you have to reboot your system after changing this value. You had to do this in the old days of Win2k, and I just don't know if this still applies to modern Windows versions. It surely doesn't hurt!
After this, phpdoc should be able to find the dot command.
The steps to resolve this error are:
download Windows Packages from
https://graphviz.gitlab.io/_pages/Download/Download_windows.html
Just install it
add c:\Program Files\Graphviz*\dot.exe or c:\Program Files (x86)\Graphviz*\dot.exe to your environment variable PATH
run phpdoc
Re-start your machine & run phpdoc (if still shows the same error message)

Compiling TCL/TK in Windows

I'm trying to get tcl/tk working in Windows 7 64bit. I've followed the readme on the main tcl's website and what I've done so far is run the make file found in the tcl8.6.1 .zip file you can get off of the tcl website. I was able to compile it with the terminal window in Visual Studio C++ 2010 professional. The make file creates a folder inside your downloaded and extracted tcl folder that you can then run and compile tcl scripts from that specific location but from nowhere else. I want to be able to compile and run tcl scripts from any directory since I'll be doing a bit of tcl/tk programming in the near future.
Stuff I've tried:
1. Copying the tclsh86t.dll file + tclsh86t.exe file to system32
2. Editing the TCL_LIBRARY environment variable but it doesn't exist :/
Any ideas?
I figured it out. In Windows:
Open a file explorer
Right click on "computer" select "properties"
Select "Advanced System Settings"
Select "Environment Variables" in the "Advanced" tab.
Edit the "Path" variable to have the location of "tclsh86t.exe" available when compiling the latest version of tcl.
When you re-open your command line, you should be able to use tclsh86t.exe from anywhere. In my case, tcl was complaining that it couldn't find a usable init.tcl file. So, I went and grabbed one from the tcl distribution and put it where it was looking and then it was fine. You can alternatively edit your TCL_Library environment variable to point to wherever it is on your PC.

Problems installing Python 27 on Windows 7 - cannot add Python to PYTHON PATH

I installed Python 2.7.3 on my Windows 7 computer using the binary, the first link. After installing it, IDLE works but nothing else recognizes Python. For example, typing python at the command prompt returns the message "'Python is not recognized as an internal or external command, operable program or bath file."
Following this post, I made sure that python 2.7 was in the PYTHONPATH environment variable. However, that didn't help.
What should I do?
PYTHONPATH system variable is used by Python itself to find directories with installed packages.
PATH system variable is used by OS (particularly Windows) to find executables which can open certain files like *.py scripts.
So, you need to add directory with python.exe (for example C:\Python27) to PATH system (or user) variable and not to PYTHONPATH. It can be done the same way as described in the link you've found in the same tool window.
For example on my machine PATH system variable is set to C:\Python27;C:\MinGW\bin;...
Like Vladimir commented, for setting up python in windows, you need to add the directory where your python.exe is located (for example C:\Python27) to PATH
You can confirm if python is in your environment variables by looking at the output of echo %path%
Keep in mind that after editing the PATH variable using the control panel, you have to open a new terminal, as the setting will NOT be updated in existing terminals.
Another possibility is that you added the wrong path to the PATH variable. Verify it.
The bottom line is, if the directory of your python.exe is really in PATH, then running python will really work.
Here are your steps:
Right-click Computer and select Properties.
In the dialog box, select Advanced System Settings.
In the next dialog, select Environment Variables. In the User Variables section, edit the PATH statement to include this:
C:\Python27;C:\Python27\Lib\site-packages\;C:\Python27\Scripts\;
Now, you can open a command prompt (Start Menu|Accessories or Start Menu|Run|cmd) and type:
C:\> python
That will load the Python interpreter!
You can install for single user rather than choosing the option of "Install for all users". I was facing the same issue, but when I tried installing just for myself, I was able to install successfully.

How to compile a Go package on Windows?

The documentation is all for Mac OS X and Linux, and I wish to know how to compile a Go package on the Windows platform. On Windows, I do not know how to write the make file and which tool to use to make it.
It seems that there is not a tool named make or go make to use with the installation file of Go development tools.
Compiling a Go package on Windows is like compiling a Go package on Linux or Mac OS X. Use the go build command. There is no make file.
Here are some instructions.
Getting Started
How to Write Go Code
Compile packages and dependencies
There are no more Makefiles needed in Go, so the make tool isn't necessary. You also do not need cygwin.
If you do not seem to have a valid go command in your windows shell, then try following the official docs on installing Go for windows
Zip archive
Extract the zip file to the directory of your choice (we suggest
c:\Go).
If you chose a directory other than c:\Go, you must set the GOROOT
environment variable to your chosen path.
Add the bin subdirectory of your Go root (for example, c:\Go\bin) to
to your PATH environment variable.
MSI installer (experimental)
Open the MSI file and follow the prompts to install the Go tools. By
default, the installer puts the Go distribution in c:\Go.
The installer should put the c:\Go\bin directory in your PATH
environment variable. You may need to restart any open command prompts
for the change to take effect.
Setting environment variables under Windows
Under Windows, you may set environment variables through the
"Environment Variables" button on the "Advanced" tab of the "System"
control panel. Some versions of Windows provide this control panel
through the "Advanced System Settings" option inside the "System"
control panel.
The last section is important. Your windows PATH environment variable needs to have C:\Go\bin, so that you will have go in your path.
from: Golang windows, a complete setup guide, http://noypi-linux.blogspot.com/2014/07/golang-windows-complete-setup-guide.html
1) download ZIP
Get the latest code from: http://golang.org/dl/
2) extract ZIP
Extract zip to example C:\local\dev\go
3) create a gopath directory,
Gopath is where third parties will be stored. Example if you will
execute a "go get github.com/somelib", this library will be stored in
gopath. Create a c:\local\dev\gopath
4) set the environmental variables
open System Properties->Advanced->Environmental Variables
GOROOT=C:\local\dev\go
GOBIN=%GOROOT%\bin
GOPATH=c:\local\dev\gopath
5) add your gobin to PATH
append C:\local\dev\go\bin to PATH
6) test
6.1) create the path "C:\local\dev\gopath\src\myfirstproject"
6.2) create the main.go file "C:\local\dev\gopath\src\myfirstproject\main.go"
package main
import "fmt"
func main() {
fmt.Println("Hi foobar")
}
6.2) you can now build the project anywhere example,
6.2.1) open cmd.exe
6.2.2) cd c:\temp
6.2.3) go build myfirstproject
6.2.4) run myfirstproject.exe
7) get a few libraries
7.1) you can download some free git, svn, and hg for windows
7.2) once you have them you can now do "go get -u github.com/somelib"
8) get an IDE
download liteide
congrats!

Resources