pyqgis standalone applicaton windows - pyqgis

Ive downloaded QGIS 3.22
according to documentation, I need to set PYTHONPANTH and PATH to make pyqgis visible from python for a stand alone application:
set PYTHONPATH=c:<qgispath>\python
such folder doesnt exist. Specificly c:\program files\qgis 3.22\python
I set the path to many folders in the directory (\apps\qgis\bin, apps\qgis\python\qgis....) but it doesnt work.
Im checking the sys.path and the new PYTHONPATH is there.
still when importing qgis.core , i get "no module qgis"
what am I missing?

Check the docs for Running Custom Applications. Make sure you have the DLL and lib folders in your PYTHONPATH. Check the environment variables using the built-in interpreter (the order of directories in PATH matters) and make sure they match your standalone environment. Also, your install should come with a python-qgis-ltr.bat or python-qgis.bat bootstrap file which is a nice starting point for setting up your own environment (on windows).

Related

How to eliminate RubyMine false "No such file to load" errors

I've recently installed RubyMine on a second machine and cloned a GitHub repository there.
My application runs exactly the same as on the first machine, but the RM code inspection result is radically different: I get dozens of "No such file to load" errors.
This even though the application runs fine both from the command line and from RM.
In dialog Run/Debug Configurations, I have specified load paths (-I. -I..) in the Ruby arguments.
Does the code inspection not honor the configuration? Or perhaps it's using a different configuration?
A bit late, but you may need to mark the directories that are load path roots in your app within the Rubymine tree - right click and do "Mark Directory As/Load Path Root".
For me the other solutions did not work. However, the problem was that RubyMine detected the wrong ruby version - while rvm for the project was ruby 2.4.1, in RubyMine it defaulted to the last version it had (2.4.2). So going to RubyMine > Preferences > Ruby SDK & Gems and changing the version for the project to the correct one solved it.
If you use the "Mark Directory As/Load Path Root" action, this will apply for IDE autocompletion only. It will not be propagated onto the interpreter (as it would be in PyCharm with Python).
You have to either keep using the -I switch, or configure $LOAD_PATH in your code, or (preferably) set up a Gem project with bundler support. You can then configure the path in a gemspec file. See https://www.jetbrains.com/help/ruby/creating-gem-project.html.
Sources:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206741945-Load-Path-not-working-at-all-
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206727915-Building-RubyGems-lib-in-load-path-
You can try changing Project Path Mappings and set relative Local Path and Remote Path to get it to work.

how to configure less in eclipse?

I downloaded the plugin from http://www.normalesup.org/~simonet/soft/ow/eclipse-less.en.html.
and installed in on eclipse however when I try to compile the less to css I get this error
Cannot be launched because of an I/O exception
Cannot run program "lessc": CreateProcess error=2, The system cannot find the file specified
can anyone whose successfully installed this guide me in the right direction ? Also xtext is installed already.
There is a similar issue for the lessc GitHub repo: issues/213
I added a new launch configuration as follows:
LESS command: lessc (existing)
Compress the generated CSS file (existing)
Use this launch configuration as default
Your have to change the "LESS Command".
Please filling your "lessc" physical path, just like "C:\Users\[Yourname]\AppData\Roaming\npm\lessc.cmd"
(Windows 7, node.js standard installer)
That means you must indicate the full path of lessc.cmd

run pydev project from file-system (with imports from different packages)

I want to run my working pydev project python code by double clicking the main module (outside of eclipse): xxx.py
The problem is that due to my imports being in different packages:
from src.apackage.amodule import obj
when xxx.py is double clicked it complains it doesn't know where the imports are (even though when I run xxx.py in pydev it magically knows what I'm importing).
A simple workaround is to remove all of the packages and move all of the modules into one directory (that obviously works but is very inconvenient)
How can I run my code in the file system without doing that work around?
This page answers my question excellently:
http://blog.habnab.it/blog/2013/07/21/python-packages-and-you/
Bottom line is always execute your code from the top, highest level, root directory (e.g. using a minimal main.py file that executes the main script of your program). Then, use absolute imports always and you never have a missing module issue since you start the program from the top directory and all imports are based off that 'home' path.
The problem you encountered is the natural behavior of most languages. A programm only knows about its working path (the path it is started in), the paths which are registered in the environment variables and at least relative paths.
The "magic" of the executable you created is therefore: It collects all scripts/modules needed, and copies/combines them next to/in the executable. The Executable then runs within the directory where all other scripts also reside and voila ...
If you are not happy with your workaround of creating an executable every time you want to run your project without PyDev there are two alternatives.
First but not the one I would suggest is registering the working path into in the environment variables.
Second and the one I think is much better: Create a link to the python executable and alter the calling string of the textfield "Target:". Append the path to your script you would like to run. Then alter the textfield "Start in:" and enter the project directory. After you did this you should be able to start your project with a simple double click.
(If you rely on external libraries which are neither on the path nor in you project you could search for appending paths temporarily to the pythonpath via the sys module.)
I hope I could help a bit.

How to distribute my Java program so that it is runnable by double-clicking a single file?

I have a Java rich client desktop app. that I want to distribute on some computers at work, but I've never done something like this before. People aren't too computer-savy at my workplace and since it is a student job, I won't be there for much longer and I'd like it if I could make my program easy to run by making it runnable when people double-click on it.
I also don't want to have to manually install a JRE to have it run. Basically, what I'd like to know is how to make my java application runnable easily by double-clicking (even if it's only on windows, it's okay). I'm pretty sure I'm going to need to package the correct JRE version alongside, but I don't know what's the correct way of doing this.
I read on some sites that you should not package a JRE along with your program because it makes people have multiple different versions, some of which are outdated, and it causes security issues, but this is not a problem in this case since the computers that are going to run my application are not connected to the internet and are only used to run this program anyway.
Somewhat related question: Since my application is currently an Eclipse project, I get my resources such as icons, images, SQLite database (for read and write), etc. using relative paths (e.g.: img/test.png).
Am I going to have to change any of those paths to have them keep working even while packaged?
What you're looking for is a JAR file. In eclipse, it's quite easy to make a Jar file. Specifically, you'll want to right click on your project, go to Export, and then select "Runnable Jar." Be careful with paths to folders. You may need to keep a resources folder next to the Jar file. You may need to provide some more specifics to get an exact answer on that. Typically, a Resources folder is located in the same spot as the JAR file (in the same folder on your computer).
A better option for easy install of a Java app. with a GUI is to launch it using Java Web Start. For the user, JWS is the 'one click' installation option that can (install & launch the app. then) add desktop shortcuts and menu items. A JWS launch would mean some more work for you, but it is a breeze for the end user.
To ensure a suitable JRE is present to run the app., use deployJava.js (see the JWS link for more details). The script would need to be reconfigured to get the JRE installer from your local network - the default is to get it from Oracle.
Most of the resources should be packaged in Jar files and supplied along with the app., but for the DB, use the JNLP ExtensionInstallerService to call the DB installer.
..Java Web Start is kind of a link (or I can make it a shortcut on the desktop) that the users will click to either install the JRE and run the program if the JRE isn't installed, or just run the program if the JRE is present on the computer.
The way it would work is to have a web page on the local intranet. When the user visits the page, the script checks for a suitable JRE.
If it is present, it writes the link to the launch file.
If there is no JRE, or the version is too low, it will guide the user through installing it (just a matter of them clicking 'OK' when prompted). Then it will put the link to the app.
I can then configure the link to grab the JRE from the server on our network.
That's the part where you need to reconfigure the script. AFAIR the script exposes an URL at which to look for JREs - that can be changed to point to a place on the intranet.
..So "Web" is only just in the name, the computers don't have to be connected to the internet to have this work, right?
Yes. JWS is a great launch technology for Java rich clients, but is a poorly chosen name.
To make the problem run by double clicking it you can distribute it as a jar file or a batch file to call the jar file.
For the installation part you can make a batch file that checks if java is present and then call the installer if it isn't.
Edit:
The batch code:
IF DEFINED JAVA GOTO ok
java-installer.exe
GOTO end
:ok
your-application.jar
:end
If you are finding it tough to implement the above mentioned methods. You can proceed with this simple approach.
Create a folder lib at a location. Place all the jars that your application uses into this. If you are able to create a jar for your application, you can very well place your application.jar into the lib folder too. Create a batch file at the same location that will contain the java command for your main class in it. The text within your batch might look something similiar to this :
set path="\lib\"
java -cp %path% package1.package2.MainClass
If you have any other dependencies, for ex: if you use images in your code under img/icon.jpg. Then you just have to shift the img folder to this location too.
Just zip these files using winrar and share it across. Running the batch file after extracting the zip would launch your java MainClass irrespective of the location in which it is placed in the client system.
PS : If you are unable to create a jar for your application and placing it in lib folder, just copy your bin folder with class files and paste it in the location and change the batch file accordingly to look for classes inside bin.

How to change the location of the netbeans settings directory (~/.netbeans)

By default netbeans stores it's settings in a directory called .netbeans under the user's home directory. Is it possible to change the location of this directory (especially under Windows)?
Thanks to James Schek I now know the answer (change the path in netbeans.conf) but that leads me to another question:
Is there a way to include the current username in the path to the netbeans setting directory?
I want to do something like this:
netbeans_default_userdir="D:\etc\${USERNAME}\.netbeans\6.5beta"
but I can't figure out the name of the variable to use (if there's any).
Of course I can achieve the same thing with the --userdir option, I'm just curious.
yes, edit the netbeans.conf file under %NETBEANS_HOME%\etc.
Edit the line with:
netbeans_default_userdir="${HOME}/.netbeans/6.0"
If you need different "profiles"--i.e. want to run different copies of Netbeans with different home directories, you can pass a new home directory to the launcher. Run "netbeans.exe --userdir /path/to/dir" or "nb.exe --userdir /path/to/dir"
"HOME" is the only variable supported by the IDE. When deploying a custom application using the Netbeans Platform, "APPNAME" is also supported out of the box.
For someone who lands up here hunting for an answer:
If you are trying to setup a portable version in windows, Netbeans 7.2 and up wont start if userdir is at the same level or lower than the Netbeans root.
So if you have:
c:\Portable\Netbeans you can NOT do netbeans_default_userdir="c:\Portable\Netbeans\userdir\8.0"
Use a folder OUTSIDE netbeans installation e.g.
netbeans_default_userdir="c:\Portable\NetbeansUserDir\8.0"
for cache it does not matter.
Tested in Windows 8.1 and 7.