1

Everytime i run my script i get:

  File "./ciinstall.py", line 35, in <module>
  import npyscreen
ImportError: No module named npyscreen

Here is my code. It checks to see if mypyscreen is installed. if not then install it then import. if it is then import. But instead its giving me an error.

# Installing npyscreen before importing npyscreen for menu UI
npy = subprocess.call(shlex.split('locate npyscreen-3.2.egg-info'))
if npy == '1':
    os.chdir('/opt/')
    subprocess.call(shlex.split('sudo wget https://pypi.python.org/packages/sou$
    subprocess.call(shlex.split('tar xvf npyscreen-3.37.tar.gz'))
    os.chdir('npyscreen-3.2')
    subprocess.call(shlex.split('sudo ./setup.py'))
    subprocess.call(shlex.split('sudo rm npyscreen-3.37.tar.gz'))

import npyscreen
0

2 Answers 2

0

According to 7-Zip on Windows, there is a Setup.py in the archive, but there is no 3.2 Directory, I have /setup.py in the root, also, the path to setup is:

\npyscreen-3.37.tar.gz\dist\npyscreen-3.37.tar\npyscreen-3.37\setup.py

os.chdir('/opt/'), puts you in /opt
wget https://pypi.python.org/packages/source/n/npyscreen/npyscreen-3.37.tar.gz, would download the tar into /opt
tar xvf npyscreen-3.37.tar.gz, should untar the package, in /opt
os.chdir('npyscreen-3.2') should be:
os.chdir('npyscreen-3.37')

then:

sudo ./setup.py
enter code here
sudo rm npyscreen-3.37.tar.gz
echo "Download and Install Finished."
import npyscreen
0

I don't like it to install packages without telling the user, but this is how I should do it:

try:
    import npyscreen
except ImportError:
    # Package not found, install it
    import subprocess
    subprocess.call(["sudo", "pip", "install", "npyscreen"])
    #TODO: check the return code for errors
    import npyscreen

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .