pip install -e . not working when multiple directory is applied - python-import

Folder Structure
Folder Structure
python-package-1
__ python_package_1
____ python_package_1
______ __init__.py
______ random_number.py
__ README.md
__ setup.py
__ setup.cfg
setup.py
setup(
name='python_package_1',
version='0.0.1',
description='This will generate random number for you!',
py_modules=\["random_number"\],
package_dir={'':'python_package_1/python_package_1'}
)
I tried running pip install -e . but from python_package_1 import random_number fails.
ImportError: cannot import name 'random_number' from 'python_package_1' (unknown location)
Is there any reason why this should not work?
I thought it would because the package_dir specifies where the files live.
build/lib has correctly copied the necessary file even!

Related

Bazel. Is there any way of running script under the same directory without `--run_under`?

Summary
I'd like to reduce the number of types when formatting.
Status quo
I am using Bazel to manage C++ project. Below is the simplified structure of the project.
❯ tree
.
├── bin
│ ├── BUILD.bazel
│ └── format.sh
├── README.md
├── src
└── WORKSPACE
Now, I'd like to format all files in src (off course, I have test in my real project) by bin/format.sh.
However, it really bothers me to type the long command below. Do you know how to make it easier?(If it is possible to change the command tobazel run bin:format, that's perfect.)
I think adding some codes in bin/BUILD.bazel would help, but I don't have any idea.
bazel run --run_under="cd $PWD &&" bin:format # format source codes
contents of files
sh_binary(
name = "format",
srcs = ["format.sh"],
)
#!/usr/bin/env sh
buildifier -r .
find . -iname *.h -o -iname *.cc | xargs clang-format -i -style=Google
I think what you are doing is fine. I would just define an alias as in
alias clang-fmt='bazel run --run_under="${PWD}" //bin:format'
You could also not use the --run_under option, and pass the directory to the program:
alias clang-fmt='bazel run //bin:format -- "${PWD}"'
and update the script
find $1 -iname *.h -o -iname *.cc | xargs clang-format -i -style=Google

Installing python module in Robomaker ROS workspace with colcon

I'm working on a cloud-based robotic application with AWS RoboMaker. I'm using ROS Kinetic, with the build tool colcon.
My robot application depends on a custom python module, which has to be in my workspace. This python module is built by colcon as a python package, not a ROS package. This page explains how to do that with catkin, but this example shows how to adapt it to colcon. So finally my workspace looks like that :
my_workspace/
|--src/
|--my_module/
| |--setup.py
| |--package.xml
| |--subfolders and python scripts...
|--some_ros_pkg1/
|--some_ros_pkg2/
|...
However the command : colcon build <my_workspace> builds all ROS packages but fails to build my python module as a package.
Here's the error I get :
Starting >>> my-module
[54.297s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'my-module' doesn't explicitly install a marker in the package index (colcon-ros currently does it implicitly but that fallback will be removed in the future)
[54.298s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'my-module' doesn't explicitly install the 'package.xml' file (colcon-ros currently does it implicitly but that fallback will be removed in the future)
--- stderr: my-module
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help
error: invalid command 'egg_info'
---
Failed <<< my-module [0.56s, exited with code 1]
I found this issue that seems correlated, and thus tried : pip install --upgrade setuptools
...Which fails with the error message :
Collecting setuptools
Using cached https://files.pythonhosted.org/packages/7c/1b/9b68465658cda69f33c31c4dbd511ac5648835680ea8de87ce05c81f95bf/setuptools-50.3.0.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "setuptools/__init__.py", line 16, in <module>
import setuptools.version
File "setuptools/version.py", line 1, in <module>
import pkg_resources
File "pkg_resources/__init__.py", line 1365
raise SyntaxError(e) from e
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-uwFamt/setuptools/
And with pip3 install --upgrade setuptools, I get :
Defaulting to user installation because normal site-packages is not writeable
Requirement already up-to-date: setuptools in /home/ubuntu/.local/lib/python3.5/site-packages (50.3.0)
I have both Python 3.5.2 an Python 2.7, but I don't know which one is used by colcon.
So I don't know what to try next, and what the real problem is. Any help welcome !
I managed to correctly install my package and its dependencies. I develop the method below, in case it may help someone someday !
I have been mainly inspired by this old DeepRacer repository.
The workspace tree in the question is wrong. It should look like this:
my_workspace/
|--src/
|--my_wrapper_package/
| |--setup.py
| |--my_package/
| |--__init__.py
| |--subfolders and python scripts...
|--some_ros_pkg1/
|--some_ros_pkg2/
my_wrapper_package may contain more than one python custom package.
A good setup.py example is this one.
You shouldn't put a package.xml next to setup.py : colcon will only look at the dependencies declared in package.xml, and won't collect pip packages.
It may help sometimes to delete the folders my_wrapper_package generated by colcon in install/ and build/. Doing so you force colcon to rebuild and bundle from scratch.

ModuleNotFoundError: No module named 'flask_restful'

I've been trying this for awhile now with no luck. Making a basic api but running into some trouble with the flask_restful module. This is my code:
import markdown
import os
import shelve
from flask import Flask, g
from flask_restful import Resource, Api, reqparse
app = Flask(__name)
#app.route("/")
def index():
with open(os.path.dirname(app.root_path) +
'/README.md', 'r') as markdown_file:
content = markdown_file.read()
return markdown.markdown(content)
This is my requirements.txt:
docker==3.4.1
docker-compose==1.22.0
docker-pycreds==0.3.0
dockerpty==0.4.1
docopt==0.6.2
Flask==1.0.2
Flask-RESTful==0.3.6
requests==2.18.4
urllib3==1.22
websocket-client==0.48.0
This is what I get as an error when running docker-compose up:
Starting python-rest_device-registry_1 ... done
Attaching to python-rest_device-registry_1
device-registry_1 | Traceback (most recent call last):
device-registry_1 | File "./run.py", line 1, in <module>
device-registry_1 | from device_registry import app
device-registry_1 | File "/usr/src/app/device_registry/__init__.py", line 6,
in <module>
device-registry_1 | from flask_restful import Resource, Api, reqparse
device-registry_1 | ModuleNotFoundError: No module named 'flask_restful'
python-rest_device-registry_1 exited with code 1
My docker file is this:
FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "./run.py" ]
What am I doing wrong here? I pip installed Flask and flask_restful but I'm lost for word on what's going on.
It does not look like you are using flask_restful in the code you are showing here. You are just importing it. It might be possible that you started out with just some flask code, which imports ok, then added flask-restful to your requirements file but docker in unaware of it and it has a cached version of that part of the container.
Try to decouple your problem, start by running your python sample outside docker, in a plain old virtualenv and make sure that starts. Then mess look into how docker is installing or not your newly added requirements.

Creating a .deb out of iOS app for Cydia repo release doesn't seem create proper .deb

I have been developing an app for an iDevice, and I wanted to create a .deb file of my app, so I created a simple app in Xcode to test things out, but I am having difficulty creating the .deb file.
I did the following steps:
1) deleted the .DS_Store files, *$ rm -rf .DS_Store*
2) $ dpkg-deb -b ~/repo/debs
When it creates the .deb file it is only 16KB which I know the test app should be a little bigger.
The directory structure for the app is as follows:
+- MyProgram
+- Applications
| +- MyProgram.app
| +- Info.plist
| +- MyProgram
| +- icon.png
+- DEBIAN
| +- control
+- System
+- Library
+- LaunchDaemons
+- com.saurik.MyProgram.plist
I didn't include a com.saurik.MyProgram.plist file because I didn't see a file resembling one in the build directory, when I built the app in Xcode.
Basically the app is a simple viewcontroller with a label. The app does contain a .storyboard file if that makes a difference.
I got this working, and created a shell script in the process. The shell script is as follows:
#!/bin/bash
echo "Update Repo Script Started"
cd ~/Projects/<ProjectName>
ldid -S app/<Project.app>/<Project>
cp -R app/<Project.app> ~/packages/<Project>/Applications/
cd ~/packages
echo $PWD
dpkg-deb -b <Project> ~/repo/debs/
cd ~/repo
dpkg-scanpackages debs / > Packages
bzip2 -fks Packages
cd ..
ssh -n <host> 'rm -rf /path/to/your/repo'
scp -r repo <host>:/home/<user>/www/
echo "Repo Updated"

ack is not doing a recursive grep

ack (the grep tool written in Perl) does not find a file that grep -r finds, and I cannot find the right options to get it to work. The following shows ack did not find the target string, which is in a regular file in a sub-directory. It's on Bash shell (Ubuntu 11.04):
100 $ grep -r imbue *
hel/find: the fact that some shells including Bash imbue braces
## Note: grep find it as shown in the above.
101 $ ./ack-standalone imbue
## Note: ack didn't find it as shown in the above.
102 $ ./ack-standalone --version
ack 1.96
Running under Perl 5.10.1 at /usr/bin/perl
Copyright 2005-2011 Andy Lester.
This program is free software. You may modify or distribute it
under the terms of the Artistic License v2.0.
## This is the testing folder structure:
103 $ tree
.
ack-standalone
hel
|- dot
|- find
|- grep
|- jobs
perlman
perlre
perlrequick
perlrun
perlvar
xargs
1 directory, 11 files
Version 2 of ack, from apt-get package installation, got same results. In the stand-alone version (version 1) shown above. ack -f shows nothing, and I tried the -r and * options, all with the same results.
On another machine, Ubuntu 10.04, it works like a charm.
It works for me if I select to operate in all files regardless of its type, using -a switch (my version is same that yours):
ack -a imbue *

Resources