Python Forum
How to add python library to Spyder
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add python library to Spyder
#1
I am trying to add an external python library from a third party software into Spyder so I can work with it. I have already tried the following:

 - Adding library path containing .py files to Tools>PYTHONPATH manager
 - Synchronizing the path
 - Updating module names list through Tools>Update Module names list

However, when I try to import modules from this library I get two types of errors:

    import easy
    Traceback (most recent call last):
    
      File "<ipython-input-2-685519d35f15>", line 1, in <module>
        import easy
    
      File "C:\Program Files (x86)\Plaxis\PLAXIS 2D\plxscripting\easy.py", line 24, in <module>
        from .server import Server, InputProcessor

      ValueError: Attempted relative import in non-package
The second type of error as follows:

from plxscripting.easy import *
    Traceback (most recent call last):
    
      File "<ipython-input-1-a40c101d3bb0>", line 1, in <module>
        from plxscripting.easy import *
    
    ImportError: No module named plxscripting.easy 
I don't understand why Spyder is not recognizing these libraries. The path has been added and shows up on the manager. What constitutes a python module? Is it not just  the .py file with module name prefix? Is not the path sufficient to work with the library through the IDE?
Reply
#2
I guess if you place your xxx.py file in the working directory it will work.

import os
os.getcwd()

Otherwise change the working directory to the directory where your file is placed.
os.chdir('C:\xxx')
Reply
#3
I don't really want to change the working directory. I want to see if there is a way to preserve the working directory but add a path variable to an additional directory... 

The reason is that if I change the working directory I might lose access to some of the other libraries that are in it.

Where can I see all the modules available to me in Spyder? Is there a list somewhere?
Reply
#4
(Apr-29-2017, 11:04 AM)awa5114 Wrote: I don't really want to change the working directory. I want to see if there is a way to preserve the working directory but add a path variable to an additional directory... 

The reason is that if I change the working directory I might lose access to some of the other libraries that are in it.

Where can I see all the modules available to me in Spyder? Is there a list somewhere?


Option 1- Place your xxxx.py file to library folder ( it may be something like C:\Programdata\Anaconda2\Lib\site-packages\)

Option 2- Click on Spyder tools menu -> PYTHONPATH manager and add the folder where your xxxx.py file is located. Then you may have to restart the spyder.

Hope this helps.

To view installed packages try below code
import pip

sorted(["%s==%s" % (i.key, i.version)
     for i in pip.get_installed_distributions()])
Reply
#5
if you google 'change python version in Spyder'
you'll find answer at top of page
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using SK Learn Library with Spyder johnfa 3 14,602 Jun-03-2021, 11:45 AM
Last Post: jefsummers
  How can I make a short-key in Spyder (Python IDE)? moose 3 2,620 Nov-02-2020, 12:13 PM
Last Post: jefsummers
  How can I scroll over my data points when creating plots in Python? (I'm using Spyder moose 0 1,581 Nov-02-2020, 07:18 AM
Last Post: moose
  Python coding in Spyder IDE fl4m3 0 2,391 Sep-26-2020, 07:03 PM
Last Post: fl4m3
  python variable issues - using spyder and opencv Afrodizzyjack 5 5,710 Jun-19-2018, 09:46 AM
Last Post: gontajones
  Python-Spyder error opening integrak20 0 3,632 Oct-20-2017, 05:44 AM
Last Post: integrak20
  Issue in launching spyder that was installed using pip install on Python 3.6.1 python300 6 10,992 Jun-02-2017, 10:44 PM
Last Post: python300
  PyInstaller, how to create library folder instead of library.zip file ? harun2525 2 4,735 May-06-2017, 11:29 AM
Last Post: harun2525

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020