Giter Site home page Giter Site logo

Comments (20)

AdrianLC avatar AdrianLC commented on July 4, 2024

Hi,

I don't have a Mac so it hasn't been tested very well with that OS.

If you save your project (command Project: Save as) and then activate a virtualenv with the plugin, the file path to the current virtualenv should show up in your *.sublime-project file. E.g: "virtualenv": "/home/user/.virtualenvs/myvenv".

You might also want to enable debug logging. You can do so from sublime's console executing this: import logging; logging.basicConfig(level='DEBUG') . Then try again and some messages will be written to the console. Here is what I'm getting:

DEBUG:Virtualenv.hooks:Running postactivate hooks.
/home/adrian/.virtualenvs/venv
DEBUG:Virtualenv.hooks:Hook execution finished.
INFO:Virtualenv.commands:Current virtualenv set to "/home/adrian/.virtualenvs/venv".
INFO:Virtualenv.commands:Command executed with virtualenv "/home/adrian/.virtualenvs/venv".
Running python -u "/home/adrian/script.py"

Hope that helps.

from sublime-text-virtualenv.

kartikkumar avatar kartikkumar commented on July 4, 2024

Thanks for the feedback. So I tried a few different things. Firstly, I created a completely new environment to make sure I wasn't messing things up somehow. I've installed numpy via pip and I just wrote a simple script that imports numpy. When I switch to working on the test environment through the Terminal, it runs fine.

In Sublime Text, I created a new project and activated the virtualenv. As a result, my project file looks as follows:

{
    "virtualenv": "/Users/kartikkumar/.virtualenvs/test"
}

I then did what you suggested and imported logging from the console, and when I run the script using the Python + Virtualenv build system, this is what appears:

>>> import logging; logging.basicConfig(level='DEBUG')
INFO:Virtualenv.commands:Command executed with virtualenv "/Users/kartikkumar/.virtualenvs/test".
Running python -u "/Users/kartikkumar/Desktop/test_project/test.py"

The build itself generates the following error:

Traceback (most recent call last):
  File "/Users/kartikkumar/Desktop/test_project/test.py", line 1, in <module>
    import numpy as np
  File "/usr/local/lib/python2.7/site-packages/numpy/__init__.py", line 170, in <module>
  File "/usr/local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
  File "/usr/local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
  File "/usr/local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
  File "/usr/local/lib/python2.7/site-packages/numpy/core/__init__.py", line 6, in <module>
ImportError: cannot import name multiarray
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "/Users/kartikkumar/Desktop/test_project/test.py"]
[dir: /Users/kartikkumar/Desktop/test_project]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

So I'm not sure what's going on. Looks like things are configured, but when running the shell_cmd, it still seems to be reverting to the system Python (which in my case is my brew Python).

Any idea what's going on?

PS: As you can see, I didn't get the debug messages that you did either. Not sure why though.

Thanks!

from sublime-text-virtualenv.

AdrianLC avatar AdrianLC commented on July 4, 2024

Try this in your script, and see what you get:

import sys

print(sys.executable, sys.version, sys.path)

Update: Sorry, forgot the most important (the path).

from sublime-text-virtualenv.

kartikkumar avatar kartikkumar commented on July 4, 2024

So from ST3, this is the output:

('/usr/local/opt/python/bin/python2.7', '2.7.9 (default, Dec 10 2014, 23:46:09) \n[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)]', ['/Users/kartikkumar/Desktop/test_project', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-7.0-py2.7.egg', '/usr/local/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg', '/usr/local/lib/python2.7/site-packages/setuptools-7.0-py2.7.egg', '/Users/kartikkumar/Desktop/test_project', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages', '/usr/local/lib/python2.7/site-packages'])

Same output from the Terminal:

('/Users/kartikkumar/.virtualenvs/test/bin/python', '2.7.9 (default, Dec 10 2014, 23:46:09) \n[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)]', ['/Users/kartikkumar/Desktop/test_project', '/usr/local/lib/python', '/Users/kartikkumar/Desktop/test_project', '/Users/kartikkumar/.virtualenvs/test/lib/python27.zip', '/Users/kartikkumar/.virtualenvs/test/lib/python2.7', '/Users/kartikkumar/.virtualenvs/test/lib/python2.7/plat-darwin', '/Users/kartikkumar/.virtualenvs/test/lib/python2.7/plat-mac', '/Users/kartikkumar/.virtualenvs/test/lib/python2.7/plat-mac/lib-scriptpackages', '/Users/kartikkumar/.virtualenvs/test/lib/python2.7/lib-tk', '/Users/kartikkumar/.virtualenvs/test/lib/python2.7/lib-old', '/Users/kartikkumar/.virtualenvs/test/lib/python2.7/lib-dynload', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/Users/kartikkumar/.virtualenvs/test/lib/python2.7/site-packages'])

As you can see, the Terminal picks up the right Python, whereas ST3 isn't. And I can confirm that the right environment is still activated in ST3, since the project file includes the virtualenv parameter pointing to the right path.

Hoping it's something small, as this would be an awesome plugin to have functioning on my Mac.

Thanks!

from sublime-text-virtualenv.

filipeximenes avatar filipeximenes commented on July 4, 2024

I'm experiencing the same problems. I'm running ST3 in Mac OS 10.9, and also using homebrew python as the default.

from sublime-text-virtualenv.

filipeximenes avatar filipeximenes commented on July 4, 2024

So... played a bit with it with no success by now.
I always launch sublime from terminal, and I've tried installing the Fix Mac Path plugin.
The path is being correctly prepared in VirtualenvExecCommand run method, but it seems to be ignored by sublime witch keeps using homebrew python /usr/local/opt/python/bin/python2.7 to execute the script instead of the virtualenv one.

from sublime-text-virtualenv.

kartikkumar avatar kartikkumar commented on July 4, 2024

Ah yes, I also launch ST3 from the terminal.

from sublime-text-virtualenv.

mcfoton avatar mcfoton commented on July 4, 2024

I have same issue — wrong python and no modules.
After selecting virtualenv "(venv) ACTIVATED" pops up for several seconds. When I try to run a build error pops up

"from selenium import webdriver ImportError: No module named selenium"

though it's installed in venv. Python shows different version too.
Here's path from error if it helps:

[path: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]

from sublime-text-virtualenv.

 avatar commented on July 4, 2024

Creates a new ~/.virtualenv just fine and can even be activated from the shell, but build system doesn't seem to reflect the updated sys.path in sublime.

from sublime-text-virtualenv.

mayuroks avatar mayuroks commented on July 4, 2024

+1 Same with me

Terminal picks correct python virtualenv

$ python -m sys -c 'print(sys.executable)' 
/Users/mrokade/.virtualenvs/gplaces/bin/python

ST3 doesnt. When I run print(sys.executable) from the script, this interpreter is picked up

/usr/bin/python

from sublime-text-virtualenv.

OmeGak avatar OmeGak commented on July 4, 2024

+1

from sublime-text-virtualenv.

dashdrum avatar dashdrum commented on July 4, 2024

Same issue. Let me know if I can help test.

PS - works great on Linux!!

from sublime-text-virtualenv.

snaily avatar snaily commented on July 4, 2024

I believe this is due to how Sublime runs subprocesses on OS X. From exec.py in the Default.sublime-package:

        if shell_cmd and sys.platform == "win32":
            # Use shell=True on Windows, so shell_cmd is passed through with the correct escaping
            self.proc = subprocess.Popen(shell_cmd, stdout=subprocess.PIPE,
                stderr=subprocess.PIPE, startupinfo=startupinfo, env=proc_env, shell=True)
        elif shell_cmd and sys.platform == "darwin":
            # Use a login shell on OSX, otherwise the users expected env vars won't be setup
            self.proc = subprocess.Popen(["/bin/bash", "-l", "-c", shell_cmd], stdout=subprocess.PIPE,
                stderr=subprocess.PIPE, startupinfo=startupinfo, env=proc_env, shell=False)
        elif shell_cmd and sys.platform == "linux":
            # Explicitly use /bin/bash on Linux, to keep Linux and OSX as
            # similar as possible. A login shell is explicitly not used for
            # linux, as it's not required
            self.proc = subprocess.Popen(["/bin/bash", "-c", shell_cmd], stdout=subprocess.PIPE,
                stderr=subprocess.PIPE, startupinfo=startupinfo, env=proc_env, shell=False)

The rationale for using a login shell presumably being that since OS X has multiple sources of PATH, inside a coder's tool like Sublime it should use whatever PATH you have in your .bash_profile. An unfortunate side effect is that it'll clobber whatever supplied PATH the build system passes along with the exec request.

I'll put together a pull request.

from sublime-text-virtualenv.

AdrianLC avatar AdrianLC commented on July 4, 2024

Someone else can test this fix?

from sublime-text-virtualenv.

kartikkumar avatar kartikkumar commented on July 4, 2024

I'll try to test it out tonight.

from sublime-text-virtualenv.

kartikkumar avatar kartikkumar commented on July 4, 2024

Excellent! Seems to be working on my system (El Capitan). Installed the package via Package Control and then overwrote the commands.py file with the one provided by @snaily and now when I activate a virtualenv from within ST3, I can access the libraries installed via pip. I double-checked by running some test code with the virtualenv activated and deactivated and it behaves as required.

So this seems to be resolved!

from sublime-text-virtualenv.

AdrianLC avatar AdrianLC commented on July 4, 2024

I just merged the PR and released a hotfix update.
Thank you @snaily and @kartikkumar for the fix and feedback!

from sublime-text-virtualenv.

kartikkumar avatar kartikkumar commented on July 4, 2024

Great! 👍

from sublime-text-virtualenv.

snaily avatar snaily commented on July 4, 2024

Woohoo!
On 8 Jan 2016 21:25, "Kartik Kumar" [email protected] wrote:

Great! [image: 👍]


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

from sublime-text-virtualenv.

xiaohk avatar xiaohk commented on July 4, 2024

I have tried the latest version on Mac OS, but I still cannot build my project properly using virtualenv.
The python is using is the system global one, not the one in the virtualenv.

When I do virtualenv:activate, I didn't get anything and the building still does not work.

Any suggestions?

from sublime-text-virtualenv.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.