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

Insert user script directory at start of sys.path (not end) #958

iangoldby opened this Issue Oct 17, 2018 · 0 comments


None yet
2 participants

iangoldby commented Oct 17, 2018

Windows 10, xlwings version 0.12.1

When I give my Python script a name that clashes with a module name in my Python environment, the RunPython() function loads the named module from the environment instead of my script. Normally Python looks for module imports in the current directory first, and then the system path.

To reproduce

  1. Set up a minimal Conda Python 3.6 environment and install xlwings. Note that even in this mininal environment the module test exists in the environment's lib directory.
  2. Create a new xlwings project called test: xlwings quickstart test --standalone
  3. Open test.xlsm, rename the _xlwings.conf sheet to xlwings.conf and set the Interpreter to point to the environment created in step 1 (e.g. C:\Users\Ian\AppData\Local\conda\conda\envs\temp\pythonw.exe)
  4. Execute the SampleCall() VBA macro.

Expected result: Script runs and writes Hello xlwings! to cell A1.
Actual result:
Traceback (most recent call last):

File "<string>", line 1, in <module>
AttributeError: module 'test' has no attribute 'hello_xlwings'


Edit the VBA code in the xlwings module: Instead of sys.path.extend(...), which puts the user script directory at the end of the path, do sys.path[0:0] = ..., which puts the user script directory first in the path.

@fzumstein fzumstein added this to the v0.13.1 milestone Oct 20, 2018

@fzumstein fzumstein closed this in f7efee6 Oct 21, 2018

fzumstein added a commit that referenced this issue Oct 21, 2018

Merge pull request #964 from ZoomerAnalytics/xltrail-958-insert-syspath
Insert user script directory at start of sys.path (not end), closes #958

@fzumstein fzumstein modified the milestones: v0.13.1, v0.13.0 Oct 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment