This forum has been archived. All content is frozen. Please use KDE Discuss instead.

KDevelop, Python and VirtualEnv

Tags: None
(comma "," separated)
Axtroz
Registered Member
Posts
3
Karma
0

KDevelop, Python and VirtualEnv

Thu Nov 27, 2014 2:59 pm
Hi there!
Will it be too hard to implement virtualenv loading in KDevelop python projects?
I know that one could use the PYTHONPATH envvar to override it but with multiple projects in multiple virtualenvs it gets inconvenient to do so.
Furthermore, setting PYTHONPATH doesn't use the interpreter from the virtualenv and I sometimes have to deploy on systems where the default interpreter is old (CentOS 6 uses 2.6 as default), but the modules require newer.

Thanks!
User avatar
int_ua
Registered Member
Posts
20
Karma
0

Re: KDevelop, Python and VirtualEnv

Sun Oct 11, 2015 12:57 pm
Even PYTHONPATH is not working, what version were you using?
https://bugs.kde.org/show_bug.cgi?id=322477
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS

Re: KDevelop, Python and VirtualEnv

Mon Oct 12, 2015 12:42 pm
The bug is just for the env vars set inside kdevelop. If you start the kdevelop process with PYTHONPATH in its env, it will resepct that, at least for finding includes.

I am not sure what you would expect from virtualenv support. What would it be supposed to do, i.e. what features could there be which would make your life easier?

Greetings,
Sven


I'm working on the KDevelop IDE.
mke21
Registered Member
Posts
1
Karma
0

Re: KDevelop, Python and VirtualEnv

Mon Nov 16, 2015 7:42 am
I am trying out kdevelop to see if it can replease eclipse/pydev for me. This is indeed one of the features that I am missing or at least that is not clear to me. Integrating virtualenv would enable me to start and debug applications in their own controlled environment that I build for this application. If each application can have their own separate virtual environment I can develop these projects in parallel in the IDE (like I do in pydev) without problems. I am actually surprised that KDevelop does not use virtual env as it is the preferred way to deploy python projects.
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS

Re: KDevelop, Python and VirtualEnv

Mon Nov 16, 2015 3:47 pm
I do not use virtualenv, Python code I write is almost always for personal or scientific use and is not deployed. Again, how exactly would integration have to look like to make it useful for you?


I'm working on the KDevelop IDE.
graemep
Registered Member
Posts
6
Karma
0
OS

Re: KDevelop, Python and VirtualEnv

Wed Mar 02, 2016 10:25 am
I have just started using Kdevelop. It is very good and kdev-python is excellent apart from the lack of virtualenv support.

There are two things needed. The most important is that auto-completion should use a particular virtualenv on a per project basis. This is particularly important if you are using a library that is either only installed in a virtual env, or you have two projects with different versions of a library that has been rearranged so import paths differ between the two versions.

The other thing required is running projects/files within the virtualenv. This is possible by configuring a script application launcher. it would be nice to be able to specify a virtualenv and have the python executable in that as the project default and the libraries in it included for autocompletion in one step, but as it is once per project configuration it is not important. It would also be easier if there was a file picker for the interpreter path as there is for the script file path.
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS

Re: KDevelop, Python and VirtualEnv

Wed Mar 02, 2016 10:54 am
Hi,

graemep wrote:There are two things needed. The most important is that auto-completion should use a particular virtualenv on a per project basis. This is particularly important if you are using a library that is either only installed in a virtual env, or you have two projects with different versions of a library that has been rearranged so import paths differ between the two versions.

Okay. Right now I think you can work around that by going to the project configuration, and under "Includes/Imports" add your library paths. Unfortunately I'm not sure this works in 4.7, but in 5.0 it will work ;)

Another workaround you can do and which certainly works is starting KDevelop with PYTHONPATH=$PYTHONPATH:/path/to/libs kdevelop, but that only works on a per-session basis of course.

I guess it would make sense to have a config option for a default python interpreter on a per-project basis. If we had that, could we get the include paths from what this interpreter thinks "sys.path" contains?

Having a file picker for the interpreter in Run is already on my todo list, because on Windows it's sort of needed anyways.

Greetings,
Sven


I'm working on the KDevelop IDE.
graemep
Registered Member
Posts
6
Karma
0
OS

Re: KDevelop, Python and VirtualEnv

Fri Mar 04, 2016 4:33 pm
If we had that, could we get the include paths from what this interpreter thinks "sys.path" contains?


I checked sys.path in a few virtualenvs and it seems to contain exactly the paths you need. Apart from the paths local to the virtualenv it includes user local and system wide paths when the virtualenv is configured to use them and excludes them when it is configured not to allow them.

I think you can work around that by going to the project configuration, and under "Includes/Imports" add your library paths. Unfortunately I'm not sure this works in 4.7, but in 5.0 it will work


Does not work in 4.7 :( Looking forward to 5.0 :), neither does setting PYTHONPATH, nor starting from the command line with the virtual env activated (which works for vim with Jedi autocompletion).

Another problem caused by not having the right paths for the virtualenv is that the problems tool view becomes very noisy with a lot of "Module not found" and "undefined variable" errors.

Despite the rough edges I really like Kdevelop for Python and it is my favourite Python IDE: it has the features I need, but it feels responsive, the UI is excellent and autocompletion works very well most of the time. Thanks for all the work you have put into it.
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS

Re: KDevelop, Python and VirtualEnv

Fri Mar 04, 2016 4:44 pm
I will see that we can get a configurable python interpreter for a project.

As a last resort re. "module not found", you can open the path containing those modules as a project. Remember that you have to press F5 in the affected files so they are actually re-analyzed.

Good to hear that some other features work well for you, though. :)


I'm working on the KDevelop IDE.
graemep
Registered Member
Posts
6
Karma
0
OS

Re: KDevelop, Python and VirtualEnv

Sat Mar 05, 2016 10:09 am
I have come across another oddity: all other imports from standard libraries are fine, but

Code: Select all
from functools import partial


gives this in the problems tool view:

Code: Select all
Declaration for "partial" not found in specified module
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS

Re: KDevelop, Python and VirtualEnv

Sat Mar 05, 2016 10:19 am
I *guess* this is https://bugs.kde.org/show_bug.cgi?id=359907 (or something similar).


I'm working on the KDevelop IDE.
graemep
Registered Member
Posts
6
Karma
0
OS

Re: KDevelop, Python and VirtualEnv

Thu Mar 24, 2016 9:10 am
Yes, that was it.

I also found that installing things user local was a good workaround. It caused problems for one module, but that is a virtualenv issue.
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS

Re: KDevelop, Python and VirtualEnv

Sun Oct 23, 2016 11:28 am
I implemented something like that now, you can configure a per-project Python interpreter in the project settings. Search paths will be retrieved from that. The feature will be available starting with version 5.1.

https://quickgit.kde.org/?p=kdev-python ... 8a465f73c2


I'm working on the KDevelop IDE.
haizaar
Registered Member
Posts
5
Karma
0
OS

Re: KDevelop, Python and VirtualEnv

Wed Oct 26, 2016 8:31 am
Great to see this feature coming to 5.1.

For now, I use the following script quite successfully. I use virtualenvwrapper and name my kdevelop sessions similarly to venv environment. Then I use the following script to launch kdevelop:

Code: Select all
#!/bin/bash

set -e

SESSION=$1
if [[ "$SESSION" == "" ]]; then
   SESSION=$(basename $VIRTUAL_ENV)
fi

ACTIVATE=$(dirname $(which python))"/activate"

SRC_PPATH=$(find $VIRTUAL_ENV/src -mindepth 1 -maxdepth 1 -type d 2>/dev/null|xargs echo |tr ' ' :)
VENV_PPATH=$(echo $VIRTUAL_ENV/lib/*/site-packages)

export PYTHONPATH=$VENV_PPATH:$SRC_PPATH:$PYTHONPATH

if kdevelop -l |grep '^\{' | grep -q $SESSION; then
   N="-s"
else
   N="-n"
fi

/bin/sh -c ". $ACTIVATE; kdevelop $N $SESSION" >&/dev/null &
disown %%
User avatar
int_ua
Registered Member
Posts
20
Karma
0

Re: KDevelop, Python and VirtualEnv

Tue Dec 08, 2020 12:58 pm
scummos wrote:by going to the project configuration

It's greyed out in the menu. I mean Project > Open configuration. It's inactive no matter what I do. Any suggestions? Kdevelop 5.5.0

Update: was able to get into project settings again after re-enabling Projects tool view. But venv imports are still not recognized yet.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]