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

Python auto completion doesn't work with $project_path config #223

Closed
mortymacs opened this issue Sep 16, 2017 · 17 comments
Closed

Python auto completion doesn't work with $project_path config #223

mortymacs opened this issue Sep 16, 2017 · 17 comments

Comments

@mortymacs
Copy link

I've set this config in my jedi-user config:

{
    "python_interpreter": "$project_path/venv/bin/python"
}

But it can't find installed packages on project venv, so auto completion doesn't work.
Note: each project has its own venv directory. for example:

Workspace/project1/venv
Workspace/projectN/venv

Thanks in advanced.

@mortymacs mortymacs changed the title Python autocompletion doesn't work with $project_path config Python auto completion doesn't work with $project_path config Sep 16, 2017
@gtalarico
Copy link

I would love to be able to do this as well, especially for python_package_paths
so it can pick up autocomplete for packages in the current venv

For example:

{
    "python_package_paths": [
                              "C:\\Users\\gtalarico\\.env\\$project_name\\Lib\\site-packages",
                             ...

@mortymacs
Copy link
Author

mortymacs commented Feb 8, 2018

@gtalarico Thank you so much, but I'm looking for $project_path because every project has its own venv in its root directory. PyCharm can find it well.

@srusskih
Copy link
Owner

srusskih commented Feb 8, 2018

oh my (: https://github.com/srusskih/SublimeJEDI/blob/master/sublime_jedi/utils.py#L311
it should be $project_path but it is $packages

going to fix this today.

@srusskih
Copy link
Owner

srusskih commented Feb 8, 2018

have pushed changes - 78736e3
@mortezaipo could you please check if it works for you?

@mortymacs
Copy link
Author

mortymacs commented Feb 8, 2018

@srusskih thanks for your update.
Auto completion doesn't work find and I've checked the console, it shows it:

Traceback (most recent call last):
  File "/opt/sublime_text/sublime_plugin.py", line 591, in on_query_completions
    res = callback.on_query_completions(v, prefix, locations)
  File "/home/morteza/.config/sublime-text-3/Packages/Jedi - Python autocompletion/sublime_jedi/completion.py", line 178, in on_query_completions
    ask_daemon(view, self._show_completions, 'autocomplete', locations[0])
  File "/home/morteza/.config/sublime-text-3/Packages/Jedi - Python autocompletion/sublime_jedi/utils.py", line 212, in ask_daemon
    DAEMONS[window_id] = Daemon(view)
  File "/home/morteza/.config/sublime-text-3/Packages/Jedi - Python autocompletion/sublime_jedi/utils.py", line 122, in __init__
    self.process = self._start_process(get_settings(view))
  File "/home/morteza/.config/sublime-text-3/Packages/Jedi - Python autocompletion/sublime_jedi/utils.py", line 160, in _start_process
    return subprocess.Popen(command, **options)
  File "./python3.3/subprocess.py", line 819, in __init__
  File "./python3.3/subprocess.py", line 1448, in _execute_child
FileNotFoundError: [Errno 2] No such file or directory: '$project_path/venv/bin/python'
Jedi - Python autocompletion.sublime_jedi.utils: Daemon process failed with next parameters: ['$project_path/venv/bin/python', '-B', 'daemon.py', '-p', 'uclipboard', '-f', ''] {'stdin': -1, 'bufsize': -1, 'universal_newlines': True, 'cwd': '/home/morteza/.config/sublime-text-3/Packages/Jedi - Python autocompletion/sublime_jedi', 'stderr': -1, 'stdout': -1}

It seems that $project_path doesn't convert to the real path.

@srusskih
Copy link
Owner

srusskih commented Feb 8, 2018

thanks. working on it.

@srusskih
Copy link
Owner

srusskih commented Feb 8, 2018

I thought I know what I'm doing, going to write some test and review this old code (:

@srusskih
Copy link
Owner

srusskih commented Feb 8, 2018

@mortezaipo can I ask you check jedi process for params ?
Could you please do something like this and share output?
Note: you need to trigger completion in sublime editor to run jedi process

$ ps ax | grep daemon.py
 7280   ??  S      0:00.84 /usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -B daemon.py -p Jedi - Python autocompletion -f required

@mortymacs
Copy link
Author

@srusskih I've checked that, there is no background process associated to jedi:

$ ps -x | grep -i jedi
79: 2155 pts/0    S+     0:00 grep -n --color -i jedi

While sublime console shows it:

reloading plugin Jedi - Python autocompletion.__init__
plugins loaded

@mortymacs
Copy link
Author

Also this is my sublime_jedi.sublime-settings configuration file:

{
	"auto_complete_function_params": "",
    "python_interpreter": "$project_path/venv/bin/python"
}

@srusskih
Copy link
Owner

srusskih commented Feb 8, 2018

sublime should run deamon.py as a subprocess could you please try this - ps ax | grep daemon.py ?

@mortymacs
Copy link
Author

mortymacs commented Feb 8, 2018

There is no process with this name too:

$ ps ax | grep -i daemon.py
236: 4109 pts/0    S+     0:00 grep -n --color -i daemon.py

@srusskih
Copy link
Owner

srusskih commented Feb 8, 2018

and completion was triggered? that's odd...

@srusskih
Copy link
Owner

srusskih commented Feb 8, 2018

what i'm trying to figure out is if the pluging uses python from settings or not.
daemon.py should be run with a python from virtualenv.
so, when completion first time triggered, daemon should be run as a subprocess and we can find out what options was passed to

@mortymacs
Copy link
Author

mortymacs commented Feb 8, 2018

@srusskih,
Problem solved, it was my mistake.
I had to save the project file (myproject.sublime-project). Daemon process will start successfully:

$ ps -x | grep daemon.py
106:20152 ?        S      0:00 /home/morteza/Workspace/myproject/venv/bin/python -B daemon.py -p myproject -f
108:20164 pts/0    S+     0:00 grep -n --color daemon.py

Now it works fine.

So there is no change required in your code (I've tested you commit and it shows error). This is my utils.py file which works fine (your old code works fine):

        subl_vars['$packages'] = sublime.packages_path()

        try:
            subl_vars['$project'] = view.window().project_file_name()
        except AttributeError:
            subl_vars['$project'] = get_project_file_name(view.window())

Kindly accept my apologize for this mistake.
Thank you so much.

@srusskih
Copy link
Owner

srusskih commented Feb 9, 2018

changes reverted :)
happy coding :)

@geruleonam
Copy link

i'm finding a way to setup python interpreter globally, it think so boring to setup Py for each project. Pyenv gimme this file as python current active environ[1] but when i setted it on global settings it seems dont work, someone can me help me?
[1] ~/.pyenv/shims/python

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

No branches or pull requests

4 participants