Manually installing a module in pythonanywhere and changing it's location - python

EDIT: So, after installing Ruamel.yaml from a local path, uninstalling it and reinstalling it worked perfectly. I have no idea why re-installing it changed anything, but hey, it works.
Please close this question.
Original:
I wanted to install the Ruamel.Yaml module for Python3.4 in
PythonAnywhere. However,if I tried to use PIP3.4 I used to get the following result:
Could not find a version that satisfies the requirement ruamel.yaml (from versions: )
No matching distribution found for ruamel.yaml
Trying to work around that, I downloaded ruamel.yaml-0.11.6.tar.gz
(the file tagged as Source), and install it with PIP3.4 using
the -e flag. Apparently, PIP3.4 told me it was a success, and
trying to re-install the package gives me the following message:
pip3.4 install --user ruamel.yaml
Requirement already satisfied (use--upgrade to upgrade): ruamel.yaml
in /home/<username>/dumpfolder_version3/ruamel.yaml-0.11.6
However, when I try to run the library I get the following error...
Traceback (most recent call last):
File "/home/<username>/mailgun/configurar_menu.py", line 3, in <module>
import ruamel.yaml as yaml
ImportError: No module named 'ruamel'
Do you have any idea what could be the problem?
If I try to reinstall another package python already has, I get this
message
pip3.4 install --user pyyaml
Requirement already satisfied (use --upgrade to upgrade): pyyaml
in /usr/local/lib/python3.4/dist-packages
Could that difference be the problem?

There might be a number of problems, but unfortunately I don't have access to pythonanywhere so I cannot test them out. I do however have some experience with ruamel.yaml and its installation ¹.
The main problem is that you try to install in editable mode, but ruamel is a namespace and pip install -e cannot properly handle that. Unfortunately ruamel.yaml's setup.py currently doesn't catch that (it does if you try to use python setup.py to install), and because of that doesn't warn or correct its behaviour.
Your site-packages directory is probably already messed up so that pip is incapable of restoring, but you can try pip uninstall -y ruamel.yaml. After that check if everything starting with ruamel is removed from your lib/python3.4/site-packages directory and reinstall with pip install ruamel.yaml*tar.gz. The latter is also what you need to do if you start from scratch.
After correct installation on 3.4 you should have the following if you do tree ruamel* in your site-packages directory:
ruamel
└── yaml
├── comments.py
├── compat.py
├── composer.py
├── configobjwalker.py
├── constructor.py
├── cyaml.py
├── dumper.py
├── emitter.py
├── error.py
├── events.py
├── __init__.py
├── loader.py
├── main.py
├── nodes.py
├── parser_.py
├── __pycache__
│   ├── comments.cpython-34.pyc
│   ├── compat.cpython-34.pyc
│   ├── composer.cpython-34.pyc
│   ├── configobjwalker.cpython-34.pyc
│   ├── constructor.cpython-34.pyc
│   ├── cyaml.cpython-34.pyc
│   ├── dumper.cpython-34.pyc
│   ├── emitter.cpython-34.pyc
│   ├── error.cpython-34.pyc
│   ├── events.cpython-34.pyc
│   ├── __init__.cpython-34.pyc
│   ├── loader.cpython-34.pyc
│   ├── main.cpython-34.pyc
│   ├── nodes.cpython-34.pyc
│   ├── parser_.cpython-34.pyc
│   ├── reader.cpython-34.pyc
│   ├── representer.cpython-34.pyc
│   ├── resolver.cpython-34.pyc
│   ├── scalarstring.cpython-34.pyc
│   ├── scanner.cpython-34.pyc
│   ├── serializer.cpython-34.pyc
│   ├── tokens.cpython-34.pyc
│   └── util.cpython-34.pyc
├── reader.py
├── representer.py
├── resolver.py
├── scalarstring.py
├── scanner.py
├── serializer.py
├── tokens.py
└── util.py
ruamel.yaml-0.11.6.dist-info
├── DESCRIPTION.rst
├── INSTALLER
├── METADATA
├── metadata.json
├── namespace_packages.txt
├── RECORD
├── top_level.txt
└── WHEEL
¹ I am the author

As edited above, this was already solved. According to Yamuel's own author, it may have been because the -e flag was messing everything up.

Related

Version on poetry.lock does not match version on GitHub

I have a private repo on GitHub containing a Poetry package which I install with
poetry add git+https://github.com/<USERNAME>/<REPO>.git#<BRANCH>
This project's structure is (assume it's called package_1)
├── README.md
├── package_1
│ ├── __init__.py
│ ├── subpackage_1
│ │ ├── __init__.py
│ │ └── subpackage_1.py
│ ├── subpackage_2
│ │ ├── __init__.py
│ │ └── subpackage_2.py
│ └── subpackage_3
│ ├── __init__.py
│ └── subpackage_3.py
├── poetry.lock
├── pyproject.toml
└── tests
├── __init__.py
└── test_package_1.py
package_1/init.py is just __version__ = "0.3.3"
When I run poetry add git+https://github.com/<USERNAME>/<REPO>.git#<BRANCH> on a new package, the package_1 package is correctly installed but two things happen which I don't understand:
1: The new package's pyproject.toml file shows package_1's version as 0.2.0 when clearly the version is 0.3.3 as mentioned above;
2: The poetry.lock file looks like this after I install package_name
[[package]]
name = "package-name"
version = "0.2.0"
...
Why is the name package-name instead of package_name (notice the _ and -)?

use namespace to install package cannot be imported

I have package structure like this:
└── src
├── my_program.py
├── mynamespace-packageone
│   ├── mynamespace
│   │   └── subpackage_one
│   │   ├── __init__.py
│   │   └── first.py
│   ├── mynamespace_packageone.egg-info
│   │   ├── PKG-INFO
│   │   ├── SOURCES.txt
│   │   ├── dependency_links.txt
│   │   └── top_level.txt
│   └── setup.py
└── mynamespace-packagetwo
├── mynamespace
│   └── subpackage_two
│   ├── __init__.py
│   └── second.py
├── mynamespace_packagetwo.egg-info
│   ├── PKG-INFO
│   ├── SOURCES.txt
│   ├── dependency_links.txt
│   └── top_level.txt
└── setup.py
in setup.py in subpackage_one,
from setuptools import setup, find_namespace_packages
PACKAGE = "mynamespace-packageone"
VERSION = "0.1"
setup(
name=PACKAGE,
version=VERSION,
packages=find_namespace_packages(include=["mynamespace.*"]),
description="subpackage_one"
)
in in setup.py in subpackage_two,
from setuptools import setup, find_namespace_packages
PACKAGE = "mynamespace-packagetwo"
VERSION = "0.1"
setup(
name=PACKAGE,
version=VERSION,
packages=find_namespace_packages(include=["mynamespace.*"]),
description="subpackage_two"
)
I use pip to install these two packages in edit mode
pip install -e src/mynamespace-packageone/
pip install -e src/mynamespace-packagetwo/
in my_program.py
I was trying to import mynamespace.subpackage_one
import mynamespace.subpackage_one
but the syntax shows cannot find module mynamespace.
I cannot figure out what is wrong.
Please help.
Thanks,
Arthur

packaging a second-level sub-directory

I have this project architecture and I want to make my_package pip installable. The project doesn't only contain stuff to package but also simple scripts (the quick and dirty kind) and over things that are important in my project but not for the package (external data for example).
my_project
├── code
│   ├── data #<-- I don't want to package this
│   │   └── make_dataset.py
│ ├── script #<-- I don't want to package this
│ │ └── make_experiment.py
│   └── my_package #<-- This is the module I want to package
│      ├── core.py
│ ├── utils.py
│      └── __init__.py
├── data
│   └── some_data.txt
├── references
│ └── reference_paper.pdf
├── reports
│ └── report.tex
├── LICENSE
├── README.md
├── requirements.txt
└── setup.py
I would like the setup.py file to be in the top-level directory so that people can do the usual
git clone gitinstance.com/my_project
cd my_project
pip install .
and get my_package module installed in their environment so they can already do python -c import my_package; print(my_package.__version__) and it works.
The question is: How can I make my_package pip-installable without putting setup.py inside the code directory?
Usually, the setup.py would look like this:
from setuptools import find_packages, setup
setup(
name='my_package',
packages=find_packages(),
version='0.1.0',
description='Research project',
author='Name',
license='MIT',
)
But it wouldn't work here because setup.py can't find my_package.
I found an example in the documentation of setuptools that more or less fit my use-case.
The solution is in the packages and package_dir arguments of the setup function that allows to specify where to find the packages to install. This is usually hidden because it defaults to the current working directory.
In my simple case, the setup.py transforms to:
from setuptools import find_packages, setup
setup(
name='my_package',
packages=find_packages(where="code"),
package_dir={'': "code"},
version='0.1.0',
description='Research project',
author='Name',
license='MIT',
)

Pip fails to install aldryn country segment requirements

I have installed aldryn-segmentation using pip and am trying to install aldryn-country-segment using pip install https://github.com/aldryn/aldryn-country-segment/archive/master.zip as the documentation suggests.
However I get an error that it could not find a version that satisfies the requirement aldryn-geoip.
Collecting aldryn-geoip (from aldryn-country-segment==0.7.2)
Could not find a version that satisfies the requirement aldryn-geoip (from aldryn-country-segment==0.7.2) (from versions: )
No matching distribution found for aldryn-geoip (from aldryn-country-segment==0.7.2)
or when downloading file and running python setup.py install it gives me this: (after lots of other text)
Processing dependencies for aldryn-country-segment==0.7.2
Searching for aldryn-geoip
Reading https://pypi.python.org/simple/aldryn-geoip/
Couldn't find index page for 'aldryn-geoip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
No local packages or download links found for aldryn-geoip
error: Could not find suitable distribution for Requirement.parse('aldryn-geoip')
Is there an obvious workaround to this?
Download and save the file somewhere in your system.
Then unzip it and cd to the directory. You'll get something like this:
.
├── addon.json
├── aldryn_config.py
├── country_segment
│   ├── cms_plugins.py
│   ├── __init__.py │   ├── locale
│   │   └── fr
│   │   └── LC_MESSAGES
│   │   ├── django.mo
│   │   └── django.po
│   ├── middleware
│   │   ├── __init__.py
│   │   └── resolve_country_code_middleware.py
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   └── __init__.py
│   ├── models.py
│   └── south_migrations
│   ├── 0001_initial.py
│   └── __init__.py
├── LICENSE.txt
├── README.md
├── schemamigration.py
└── setup.py
7 directories, 17 files
Then run sudo python setup.py install and python will install the package to your system.
You may need to install aldryn-geoip as dependency too. (using the same way)

setup.py develop not respecting package kwarg

My folder structure looks like
.
├── my_package
│   ├── A.py
│   └── __init__.py
├── my_package2
│   ├── B.py
│   └── __init__.py
└── setup.py
And my setup.py looks like
from setuptools import setup
if __name__ == '__main__':
setup(name='my_packages',
packages=['my_package'])
When I run
python3 setup.py develop
The egg file is created locally and an egg-link file is placed in my site-packages directory. Also, the folder is added to easy_install.pth which means that both my_package and my_package2 are importable. This is different than running python3 setup.py install (only my_package would be available per the keyword argument passed to the setup function).
This same behavior occurs when installing with pip using the -e flag.
Is this intended behavior? Is there any way to replicate the functionality of install using develop?

Categories