Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Support virtualenv #75

Closed
crucialfelix opened this issue Oct 7, 2015 · 16 comments
Closed

Support virtualenv #75

crucialfelix opened this issue Oct 7, 2015 · 16 comments

Comments

@crucialfelix
Copy link

I cannot yet find anyway to make linter-pylint work in a virtualenv. For python development it is essential. There should be a simple per-project way to indicate a virtualenv.

We have thousands of import errors, and all the attribute checks with parent classes don't work.

Setting the executable in the (global) settings as described in the docs does not work:

  "linter-pylint":
    rcFile: "/Users/crucial/Sites/nestseekers/.pylintrc"
    executable: "/Users/crucial/.virtualenvs/ns/bin/pylint"

F: 3, 0: Unable to import 'globalapp.admin' (import-error)
etc. etc.

To run pylint on the command line without having activated the virtualenv, I can do this:

PYTHONPATH=${PYTHONPATH}:$(dirname %d) /Users/crucial/.virtualenvs/ns/bin/python /Users/crucial/.virtualenvs/ns/bin/pylint

That runs pylint correctly with no import errors.

Note that includes the current project directory and runs it with the python and pylint installed in the virtualenv

But that cannot be set in the config

  "linter-pylint":
    rcFile: "/Users/crucial/Sites/nestseekers/.pylintrc"
    executable: "PYTHONPATH=${PYTHONPATH}:/Users/crucial/Sites/nestseekers /Users/crucial/.virtualenvs/ns/bin/python /Users/crucial/.virtualenvs/ns/bin/pylint"
Failed to spawn command PYTHONPATH=${PYTHONPATH}:/Users/crucial/Sites/nestseekers /Users/crucial/.virtualenvs/ns/bin/python /Users/crucial/.virtualenvs/ns/bin/pylint. Make sure PYTHONPATH=${PYTHONPATH}:/Users/crucial/Sites/nestseekers /Users/crucial/.virtualenvs/ns/bin/python /Users/crucial/.virtualenvs/ns/bin/pylint is installed and on your PATH
@art-solopov
Copy link

+1.
I tried setting the executable to /usr/bin/env pylint, but it doesn't seem to work, producing an exception:

Uncaught BufferedProcessError: Failed to spawn command `/usr/bin/env pylint`. Make sure `/usr/bin/env pylint` is installed and on your PATH

@surfer190
Copy link

@art-solopov @crucialfelix Isn't this issue fixed by changing config...

Executable Path to your pylint executable. This is useful if you have different versions of pylint for Python 2 and 3 or if you are using a virtualenv. Use %p for the current project (no trailing /).

Not sure how to set this up though...maybe in config.json:

"linter-pylint":
path: "~/projects/envs/my-env"

@crucialfelix
Copy link
Author

I'm using https://atom.io/packages/linter-pylama now. This combines pylint
pep8 pyflakes pep257

but I see from my config file that when I was using pylint I did this:

"linter-pylint":
rcFile: "/Users/crucial/Sites/nestseekers/.pylintrc"
executable: "/Users/crucial/.virtualenvs/ns/bin/pylint"
pythonPath: "%p"

that means the virtualenv's own installed pylint is used so it always uses
the right python and the right paths
and there is no need to tell pylint about which virtualenv to use or
activate.

On Sat, Jan 9, 2016 at 1:35 PM surfer190 [email protected] wrote:

@art-solopov https://github.com/art-solopov @crucialfelix
https://github.com/crucialfelix Isn't this issue fixed by changing
config...

Executable Path to your pylint executable. This is useful if you have
different versions of pylint for Python 2 and 3 or if you are using a
virtualenv. Use %p for the current project (no trailing /).

Not sure how to set this up though...maybe in config.json:

"linter-pylint":
path: "~/projects/envs/my-env"


Reply to this email directly or view it on GitHub
#75 (comment)
.

@crucialfelix
Copy link
Author

It does kind of suck in that Atom will always use that python virtualenv
for all python projects.

It should be per-project, preferably just by detecting a setup.cfg or
.pylintrc and getting the virtualenv from there.

we shouldn't have to set these things in our editors.

On Sat, Jan 9, 2016 at 3:13 PM Chris Sattinger [email protected]
wrote:

I'm using https://atom.io/packages/linter-pylama now. This combines
pylint pep8 pyflakes pep257

but I see from my config file that when I was using pylint I did this:

"linter-pylint":
rcFile: "/Users/crucial/Sites/nestseekers/.pylintrc"
executable: "/Users/crucial/.virtualenvs/ns/bin/pylint"
pythonPath: "%p"

that means the virtualenv's own installed pylint is used so it always uses
the right python and the right paths
and there is no need to tell pylint about which virtualenv to use or
activate.

On Sat, Jan 9, 2016 at 1:35 PM surfer190 [email protected] wrote:

@art-solopov https://github.com/art-solopov @crucialfelix
https://github.com/crucialfelix Isn't this issue fixed by changing
config...

Executable Path to your pylint executable. This is useful if you have
different versions of pylint for Python 2 and 3 or if you are using a
virtualenv. Use %p for the current project (no trailing /).

Not sure how to set this up though...maybe in config.json:

"linter-pylint":
path: "~/projects/envs/my-env"


Reply to this email directly or view it on GitHub
#75 (comment)
.

@Arcanemagus
Copy link
Member

@crucialfelix You are already using the solution to this in part of your configuration, you just didn't to use it in the rest for some reason.

%p is expanded to the current project's base folder in the paths you configure, so as long as the path to the virtualenv doesn't change per project you should be able to use that.

@crucialfelix
Copy link
Author

You are already using the solution to this in part of your configuration,
you just didn't to use it in the rest for some reason.

Sorry, I don't quite understand what you mean.

I got it to work with virtualenvs by specifying the executable. I'm sharing
that information for people in this thread who were not able to get it to
work by using other means.

so as long as the path to the virtualenv doesn't change per project you
should be able to use that.

Well that would be completely useless for any programming projects I can
think of. Each project has its own virtualenv.

On Sun, Jan 10, 2016 at 11:36 AM Landon Abney [email protected]
wrote:

@crucialfelix https://github.com/crucialfelix You are already using the
solution to this in part of your configuration, you just didn't to use it
in the rest for some reason.

%p is expanded to the current project's base folder in the paths you
configure, so as long as the path to the virtualenv doesn't change per
project you should be able to use that.


Reply to this email directly or view it on GitHub
#75 (comment)
.

@Arcanemagus
Copy link
Member

You have hardcoded the paths to the rcFile and the pylint executable to a single project's version, but then for the pythonPath you have utilized the %p shortcut to point to the current project's folder.

By "path to the virtual env" I meant the relative path to the project's virtualenv binaries, from the project's root folder.

I could also be completely off base here, @SpainTrain is the one who put this all together 😉.

@ghost
Copy link

ghost commented Jan 10, 2016

The most straightforward way of dealing with this is to have your virtualenvs in the project directory so you can then set the path to %p/venv/bin/python or something similar. Having completely different absolute paths per project would require separate package settings per-project which I suspect is out of the scope of an add-on package like this. Project support is probably one of Atom's biggest weak points but there are okay solutions like atom-project-manager that will allow you to configure settings that will be automatically applied to your config.cson when opening a specific project.

@crucialfelix
Copy link
Author

@Arcanemagus OK, now I get you. Thanks.

Putting the virtualenv in the folder is possible but non-ideal. I already do this all the time with node_modules though. mkvirtualenv doesn't seem to have an option of where to place the packages, its always in ~/.virtualenvs for me.

@joelcolucci
Copy link

joelcolucci commented May 6, 2016

I have my venv directory in my project.
I've set Executable to %p/venv/bin/python.
When opening a .py file I get the red box error stating:

Error: Unknown option: -- usage: 

Has anyone see this before?

@xtianjohns
Copy link

xtianjohns commented May 17, 2016

@joelcolucci, my guess is that your issue involves setting the Executable to python, rather than pylint.

Try installing pylint in your virtual environment if you haven't already, then update to %p/venv/bin/pylint. Does that help?

@joelcolucci
Copy link

@xtianjohns That did it. Somehow missed an easy one. Thanks for your time!

@Arcanemagus
Copy link
Member

Marking this as closed, as far as I can tell the required functionality is already implemented by the PYTHONPATH and executable expansions available allowing paths relative to the project to be used.

@hobbeshunter
Copy link

I'm also trying to set up virtualenv.

I set

  • Executable Path to %p/env/bin/pylint
  • Python Parth to %p/env/bin/python3
    and
  • Working Directory to %p/src

Even though pylint is installed and working from cli in this virtualenv I get following error printed to the atom dev console:

linter-registry.js [sm]:137 [Linter] Error running Pylint Error: Traceback (most recent call last):
  File "/home/me/xxx/env/bin/pylint", line 11, in <module>
    sys.exit(run_pylint())
  File "/home/me/xxx/env/lib/python3.5/site-packages/pylint/__init__.py", line 13, in run_pylint
    Run(sys.argv[1:])
  File "/home/me/xxx/env/lib/python3.5/site-packages/pylint/lint.py", line 1254, in __init__
    linter.read_config_file()
  File "/home/me/xxx/env/lib/python3.5/site-packages/pylint/config.py", line 633, in read_config_file
    with io.open(config_file, 'r', encoding='utf_8_sig') as fp:
IsADirectoryError: [Errno 21] Is a directory: '/home/me/xxx/'
    at Object.<anonymous> (/home/me/.atom/packages/linter-pylint/lib/main.js:161:17)
    at next (<anonymous>)
    at step (/home/me/.atom/packages/linter-pylint/lib/main.js:7:273)

I'm working on Ubuntu Linux.

@ddaanet
Copy link
Contributor

ddaanet commented May 22, 2017

@hobbeshunter You have a configuration issue: it looks like you specified "%p" as the the pylint configuration file path, in the linter-pylint settings, instead of something like "%p/pylintrc".

This is not a problem with virtualenv support in pylint, which works just fine.

@ojob
Copy link

ojob commented Sep 19, 2019

Hi All,
For the records, configuration under Windows is as follows, even though I cannot really get the magic behind: $PIPENV_PATH\Scripts\python.exe

%p is not recognized. Backslashes may not be necessary.

For quick&dirty coding, not sure this is a nice solution though, as you need to setup a virtualenv for each of them.

Happy coding !

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

No branches or pull requests

10 participants