Install sage script using setuptools - python

I am trying to build an installer for a sage script using setuptools. Here is what I have.
My setup.py file:
#!/usr/bin/env python2
from setuptools import setup
__name__ = 'sage-test'
__version__ = '0.0'
setup(name=__name__,
scripts=['sage-test'],
)
The sage-test file:
#!/usr/bin/env sage
from sage.all import GF
print(GF(5))
I now do ./setup.py build and ./setup.py install. When I try to run sage-test, I get the following error:
Traceback (most recent call last):
File "/usr/bin/sage-test", line 4, in <module>
__import__('pkg_resources').run_script('sage-test==0.0.0', 'sage-test')
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 517, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 1443, in run_script
exec(script_code, namespace, namespace)
File "/usr/lib/python2.7/site-packages/sage_test-0.0.0-py2.7.egg/EGG-INFO/scripts/sage-test", line 3, in <module>
__requires__ = 'sage-test==0.0.0'
ImportError: No module named sage.all
Any ideas how to get this to work? (Note that I can run ./sage-test within the current directory and everything works.)

This may not help, but this looks suspicious.
/usr/lib/python2.7/
Maybe you need to do everything within sage -sh - I wouldn't be surprised if there was some env var that was not set up properly. I don't know exactly why but maybe it's picking up your system Python somehow.

Related

Package not found on virtualenv - No module named "mypack"

Hi !
I've tried to use a package I've created (named mypackage) on my main program (named collector). mypackage is defined with the setup.py below:
name = "mypackage"
[...]
packages = find_packages(),
include_package_data = True,
exclude_package_data = { '': ['README.md'] }
[...]
entry_points = {
'console_scripts': [
'my-package=mypack.mypack:main'
]
},
I want to use a little program present this package, which will normally be called as below on collector:
from mypack.common.prog import mylittleprogram
I've tried to install mypackage on a virtualenv, and then (re)installed my main program. Then I executed it, and there is the error I have:
Traceback (most recent call last):
from project.common.collector import collectArt
File "/root/project/lib/python3.5/site-packages/collector-0.1-py3.5.egg/project/common/collector.py", line 7, in <module>
ImportError: No module named 'mypack'
Also, when the virtualenv is activated, I've just tried to launch the entry-point named my-package:
Traceback (most recent call last):
File "/root/project/bin/my-package", line 11, in <module>
load_entry_point('mypackage==0.1.1', 'console_scripts', 'my-package')()
File "/root/project/lib/python3.5/site-packages/pkg_resources/__init__.py", line 560, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/root/project/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2648, in load_entry_point
return ep.load()
File "/root/project/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2302, in load
return self.resolve()
File "/root/project/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2308, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
ImportError: No module named 'mypack'
Note 1: I precise that I have the __init__.py on each folder of my package.
Note 2: the virtualenv folders are on the same folder as my main program.
How do I use mylittleprogram present on mypackage on my collector main program with virtualenv ? Did I made something wrong ?
Thank you :)
There is the issue, I had to install my package via the following command:
python setup.py develop
And then the package is recognized. This command has to be executed when the virtualenv is activated, and be executed on the directory of the package.
Hope this will help someone in the future !

If I have Pandas installed correctly, why won't my import statement recognize it?

I'm working on a project to play around with a csv file, however, I can't get pandas to work. Everything I have researched so far has just told me to make sure that pandas is installed. Using pip I have managed to install pandas just fine. When I try to run my python program and import pandas I get:
Traceback (most recent call last):
File "analysis.py", line 1, in <module>
import pandas as pd
ImportError: No module named pandas
I don't know if this is related, but I was trying to see see if this would work with conda install pandas however, I get this import error:
(Again, Anaconda is correctly installed on my system)
Traceback (most recent call last):
File "/usr/local/bin/conda", line 9, in <module>
load_entry_point('conda==4.2.7', 'console_scripts', 'conda')()
File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 561, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 2627, in load_entry_point
return ep.load()
File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 2287, in load
return self.resolve()
File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 2293, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/Library/Python/2.7/site-packages/conda/cli/__init__.py", line 8, in <module>
from .main import main # NOQA
File "/Library/Python/2.7/site-packages/conda/cli/main.py", line 46, in <module>
from ..base.context import context
File "/Library/Python/2.7/site-packages/conda/base/context.py", line 18, in <module>
from ..common.configuration import (Configuration, MapParameter, PrimitiveParameter,
File "/Library/Python/2.7/site-packages/conda/common/configuration.py", line 40, in <module>
from ruamel.yaml.comments import CommentedSeq, CommentedMap # pragma: no cover
ImportError: No module named ruamel.yaml.comments
Anyone have a similar experience importing libraries? I have tried to make sure that I have the correct versions for Python3 but that doesn't seem to be the issue. Any help would be greatly appreciated! Thank you.
The problem is that the 'lib' folder that pip installs things into has a separate subdirectory for each python environment that you're working with (by default this is python2.7). A simple workaround is to build a virtual environment of python3 and then installing pandas or whatever package you want into it. To achieve this, try the following:
virtualenv -p /usr/bin/python3 python3
Now, each time you want to pip install a python3 package, run
source python3/bin/activate
pip install pandas --user
Hope this helps
Go to powershell on your system and pip install pandas. you will see a successfully installed command. you can install other modules too like matplotlib et al.

Virtualenv doesn't work on RedHat

I'm trying to figure out why I cannot create a virtualenv on RedHat. Here's my command line :
python /opt/rh/python27/root/usr/bin/virtualenv-2.7 -p /opt/rh/python27/ /home/myuser/tpa/
.
/opt/rh/python27/root/usr/bin/virtualenv-2.7 : Is here to setup the version of virtualenv that I want to use
-p /opt/rh/python27/ : To setup the version of python I want to use
/home/myuser/tpa/ : My directory where the virtualenv will be stored
But I get the following :
Traceback (most recent call last):
File "/opt/rh/python27/root/usr/bin/virtualenv-2.7", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 2603, in <module>
File "/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 666, in require
File "/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 565, in resolve
pkg_resources.DistributionNotFound: virtualenv==1.10.1
Do you have any idea?
Thanks
-p expects a python executable, not an installation directory. Give it the name of a python executable in your $PATH or the full path the the python executable you want to run.

Passing Python3 to virtualenvwrapper throws up ImportError

I'm trying to use the virtualenvwrapper to make a python 3 based virtualenv. However,I'm when I pass the optional interpreter argument, I'm seeing this error. I'm running Ubuntu 15.04. I tried reinstalling virtualenv and virtualenvwrapper without success. Thanks for all your help!
$ mkvirtualenv scriptcutter --python=/usr/bin/python3
Running virtualenv with interpreter /usr/bin/python3
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in apport_excepthook
if not enabled():
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Original exception was:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
I come across same issue, but after I downgrade virtualenv to 12.0.2, this problem disappears.
This is sort of a workaround for now.
Create a virtualenv using pyvenv.
# install pyvenv on Ubuntu
sudo apt-get install python3-venv
To minimize disruption in your normal workflow, pass a destination directory that is the same as the one used by virtualenvwrapper Like so,
pyvenv example ~/.virtualenvs/example
This is automatically working with workon and cdproject commands. I don't use much else that is provided by virtualenvwrapper
Hope this helps.
You can upgrade to the most recent version of virtualenv, with:
sudo pip install --upgrade https://github.com/pypa/virtualenv/archive/master.zip
virtualenv --version
# Returns 15.2.0.dev0 when I ran it
The following command then works:
mkvirtualenv scriptcutter --python=/usr/bin/python3
Apparently, the develop branch was dropped, so the URL with "develop" will no longer work. My answer was based off of #pjotr_dolphin's comment, with the URL updated.

Upgrading py2app with pip breakes it

I upgraded py2app (using pip) and then ran
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/bin/py2applet --make-setup --arch=i386 test.py
However I get the following
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/bin/py2applet", line 5, in <module>
from pkg_resources import load_entry_point
File "/Library/Python/2.7/site-packages/pkg_resources.py", line 2797, in <module>
parse_requirements(__requires__), Environment()
File "/Library/Python/2.7/site-packages/pkg_resources.py", line 576, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: py2app==0.6.3
I don't want to use 0.6.3 why is it forcing me to?
It looks like the py2applet shell script has an explicit exit call that checks the py2app version. Updating it to the latest seemed to do the trick. I have two parallel installs of python, the native OS X one and one from MacPorts. Somehow the py2applet script wasn't taken into account after updating the port. I wouldn't recommend this method for other distributions but on a Mac this seems to me a viable solution.
#!/usr/bin/python
__requires__ = 'py2app==0.8'
import sys
from pkg_resources import load_entry_point
sys.exit(
load_entry_point('py2app==0.8', 'console_scripts', 'py2applet')()
)
By the way you can find the version number by importing py2app in the python shell:
python
import py2app
py2app.__version__
Gives me:
'0.8'

Categories