I currently have a stable version of APP running on my system. I aim to create a new version of APP but I still need the stable version to run while I do so. I cloned the repository of APP and I encounter the following problem:
Lines of the form from XXX import YYY do not import the local file (cloned repo) but imports the ones at /usr/lib/python3/dist-packages/APP/XXX.py that where created by the stable version.
How can I change that (in VSCode) ?
This question has probably already been asked, but I have been unable to find an answer. If someone could redirect me towards an adequate answer, that would be awesome.
Remove the APP module from dist-packages.
Related
A very simple question with a lot of context behind it, so thanks in advance for your patience. In summary I am attempting to control a DAC/ADC development board by adapting already existing software written in python. However, I am encountering an error when I simply try to import some of the prerequisites.
The board I am attempting to control is the ZCU111. The ZCU111 has an ARM processor on board and some wonderful folks found a way to put linux on board; Pynq. The pynq software is imaged onto a SD card, and the SD card is mounted onto the ZCU111 board and the processor boots from the card. I communicate to the board through a USB serial interface and a hosted SSH server on the ZCU111.
Using pynq, some modules have been created to control automatically set the inner workings of the ZCU111 board, ZCU111 GitHub.
Using those modules someone created some great Jupiter notebooks that help run the ZCU111 though a nice gui interface; RFSoC_SAM. However, I dont want run the board through a notebook or gui, I wanted to adapt parts of the code to a much simpler .py file to be run from the terminal.
image of filing system on SD card
To the left is an image of the filing system on the SD card. The GitHub folder contains the modules to control the inner workings, and its identical to the link above. The Jupiter notebook folder contains the notebook which I wish to emulate and works as expected. The pynq folder contains the modules for pynq itself. The Sami_py folder is where I placed my test code.
Here are where my problems and questions begin: The Notebook that works begins with 2 lines of code:
from rfsoc_sam.overlay import
sam = Overlay()
When I scour the SD card, I can't find rfsoc_sam anywhere on the SD card. I'm confused how it works? The GitHub listed above for the RFSoC_Sam DOES have the accompanying .py files. Why do'nt those .py files appear on my SC card? Does the Jupiter notebook package all the necessary files? Regardless the first step in creating my own software is to import the same modules the Overlay from the rfsoc_sam module does. Despite it not appearing on the SD card, I can open the file from the GitHub
from pynq import Overlay, allocate
import xrfclk
import xrfdc
import os
from .hierarchies import *
from .quick_widgets import Image
from ipywidgets import IntProgress
from IPython.display import display
from IPython.display import clear_output
import time
import threading
That is everything that needed to be imported, however I just wanted to start with xrfclk. Since that folder and init file can be found on the SD card in the GitHub folder, the same folder from the link above, ZCU111 GitHub.
I wrote a .py file placed in the Sami_py folder:
import sys
sys.path.insert(1, '//192.168.2.99/xilinx/GitHub/ZCU111-PYNQ/ZCU111/packages/xrfclk')
import xrfclk
The error message I receive:
Traceback (most recent call last):
File "Sami_py/RFSoC_Trial.py", line 3, in <module>
import xrfclk
ImportError: No module named xrfclk
I thought I pointed to the right directory, do i need to point to the directory that has the init file directly? I am not sure why i can't get the include to work, any thoughts?
Happy to provide more context. Thanks in advance for any help or advnce,
Sami
I'm sorry to hear you're having problems with RFSoC SAM. I created this project and can give you some help about RFSoC and PYNQ.
Firstly, the RFSoC SAM package is installed and maintained using pip, which is the python package manager. As PYNQ v2.6 uses Python3, we need to invoke the pip3 command to install RFSoC SAM. In the repository readme, you will see that installing RFSoC SAM on the ZCU111 has a few steps. You need to connect your board to the internet for these steps to work correctly. You should also use the terminal in the Jupyter Labs environment to run the commands (this is detailed in the repository readme). The first step is a patch for the xrfdc package, and looks a bit like this:
mkdir /home/xilinx/GitHub cd /home/xilinx/GitHub/ git clone https://github.com/dnorthcote/ZCU111-PYNQ cd /home/xilinx/GitHub/ZCU111-PYNQ cp /home/xilinx/GitHub/ZCU111-PYNQ/ZCU111/packages/xrfdc/pkg/xrfdc/__init__.py /usr/local/lib/python3.6/dist-packages/xrfdc/__init__.py
The reason a patch is required is because the xrfdc package needs an update that has not yet been implemented for the ZCU111, but it has been implemented for the RFSoC2x2. I simply moved these updates over to the ZCU111, which means RFSoC SAM will function correctly. If you do not implement this patch, the notebook for RFSoC SAM will fail to load. I am not in charge of the xrfdc package, which is why the package needs to be patched (not version controlled and updated).
After implementing the xrfdc patch, you can install RFSoC SAM via pip. The command looks a bit like this:
pip3 install git+https://github.com/strath-sdr/rfsoc_sam
This command will install the RFSoC SAM package to the following location:
/usr/local/lib/python3.6/dist-packages/rfsoc-sam
This location is where all pip packages are stored for PYNQ v2.6. You should not attempt to directly modify packages in this location as they are all under version control. If you would like to develop and change the RFSoC SAM source code, then you need to consider a slightly different workflow.
The RFSoC SAM package does not have any developer tools. To make changes to the project, I simply Git clone the project to my Jupyter workspace in PYNQ, and then make changes to the project. When I'm ready, I can simply reinstall the package by running the following command in a Jupyter Labs terminal:
pip3 install .
This command will just reinstall RFSoC SAM, but using the offline changes you make instead. Using this workflow, you could easily create a fork of RFSoC SAM, make changes to the source code, commit those changes, and easily install the package on your ZCU111. This workflow is something you should consider.
You may be more interested in trying out RFSoC + PYNQ projects that are of lower complexity. For instance, you will be able to see the following projects: RFSoC QPSK and RFSoC Radio. You may have also seen the RFSoC Workshop.
Going forward, I would recommend investigating the above projects, and also understanding Linux and pip a little better. A few google searches should get you on the right path here. Try to create your own pip package and a Github repository to store the package. If you can do this, you will have greatly improved your understanding of pip, and the PYNQ operating system.
Also, If you have questions in the future, you can use the [PYNQ discussion page] (https://discuss.pynq.io/). I will be able to find your questions faster here.
If you have any further issues, feel free to drop me a message. You can also use the RFSoC SAM issues page in the repository, which helps me track these type of questions a little easier.
David N.
I'm a beginner in Python and I have no experience with GitHub at all. I want to import the module semsimlib from the following URL: https://github.com/timvdc/semsimlib
I have looked on the internet for help on how to do this but most of it is very unclear and doesn't seem to work for me. Can anyone provide a detailed explanation on how to do this in a easy way?
It looks the repo does not provide appropriate scripts to simply install the package. There is no setup.py file and there is no distribution on pypi.
What you can do is go to site-packages folder inside your python installation or inside your virtual environment. Then run git clone https://github.com/timvdc/semsimlib. You should now be able to import semsimlib. Keep in mind that you will also have to install all the other dependencies your self one by one since there is also no requirements file.
You can also clone the repo into any folder on your computer and at the top of your script put:
import sys
sys.path.append("path/to/semsimlib/folder")
semsimlib will now be importable. However, I would try to get it to work with the first method.
I am trying to push a flask app (Python 3.5) to Cloud Foundry (CF). The application takes a POST request (text file) and returns a message. It works locally (tested via Postman). However, when attempting to push it to CF, it gives the error -
ImportError: No module named queue
Here is my code which contains queue.
import queue as Queue
self._batch_queue = Queue.Queue(self.BATCH_QUEUE_MAX)
self._example_queue = Queue.Queue(self.BATCH_QUEUE_MAX * self._hps.batch_size)
I've tried the solutions suggested here, but neither of these solve my problem. I think the issue is with the Python in CF not having queue package. (I could be wrong).
Anyone ideas on how to go about solving this will be very appreciated. Thanks in advance!
As mentioned in the comments by #KlausD, it seems like you have the wrong version of Python installed. On Cloud Foundry, you would set the version by including a file called runtime.txt in the root of your project (i.e. the directory from which you're running cf push).
https://docs.cloudfoundry.org/buildpacks/python/index.html#runtime
That file is used to tell the Python buildpack which version of Python to install for you. Suggestions would be python-3.5.x or python-3.6.x which would install the latest 3.5 or 3.6 release. You can specify an exact version like python-3.5.5 but it's not recommended as it's easy to forget to update that file when new versions of Python come out.
You can see which versions of Python are supported by the buildpack here.
https://buildpacks.cloudfoundry.org/#/buildpacks/python/v1.6.17
(Note that link goes to the latest version of the buildpack at the time I wrote this, it will get out of date. In the future, just click the most recent version of the buildpack to see what ships with it).
Well I'm trying to use Datastore in a personal project using the Google App Engine. Though, I can't import the datastore module, no matter how hard I try.
I've been using the online console during the whole time (in order to avoid to have to solve problems first on my PC and then on GCloud...)
So, I'm using
from google.cloud import datastore
Unfortunately, that's not working at all. The last error I have is
ImportError: No module named google.protobuf
But before I had things like Can't import Datastore.
What I did was removing the integrality of /lib, and reinstalling every dependancy with pip. Here is my requirements.txt:
# This requirements file lists all third-party dependencies for this project.
#
# Run 'pip install -r requirements.txt -t lib/' to install these dependencies
# in `lib/` subdirectory.
#
# Note: The `lib` directory is added to `sys.path` by `appengine_config.py`.
Flask==0.10
google.cloud==0.25.0
protobuf==3.3.0
(The last line was added to try to resolve the last error I got). Before having this error, I got
Also, a little clarification question: I've seen (while looking for answers) people using gcloud and some using google.cloud. What's the difference? What should I use?
Also, pip show google.cloud shows nothing.
What am I missing?
Thank you
Well, if anyone is wondering, here's how I solved the problem. What fixed it was changing the Flask version to 0.12 (don't know why, but that's what happened).
I deleted lib to be sure I was starting from scratch. Then, I used this requirements.txt file:
Flask==0.12
google-cloud==0.25.0
click==5.1
(click is needed by Flask 0.12).
I have a Flask project which I've put the flask module (version 0.9) directly beside my app.py file. I've done this so that I can bundle everything into a version control repository that won't require anyone else using it to install additional Python modules.
I want to use flask-login so I've tried to manually install it by downloading the latest version and putting the flask_login.py file in my "local" flask/ext/ directory. However, while I can import flask and import flask.ext, I am unable to import flask.ext.login with Python throwing ImportError: No module named flask.ext.login. import flask.ext.flask_login throws an import error as well.
Is there something I have to do differently if Flask and it's extensions are local to the app.py?
The solution is to put the flask_login.py file in the same directory as my app.py file. No modification of the flask/ext/__init__.py file is necessary.
The flask.ext module is intended only as a an extension importer, not a repository for installed extensions. Based on the import path, I thought the flask/ext folder was where extensions were to be copied. This was incorrect. Extensions simply need to be somewhere on the python path.
Python doesn't throw the exception in your case, this Flask module is responsible for modifying the standard import hook in the ext folder:
https://github.com/mitsuhiko/flask/blob/master/flask/exthook.py
So, I don't think putting flask_login.py into flask/ext is the right way to use extensions in Flask. The documentation recommends to use pip install flask-login or python setup.py install. After that you can do:
import flask_login
If you still want to do it manually, remove the setup() call from ext/__ init__.py.
It probably has a good reason why the Flask guys did it this way though :-)
Right, but the point was to manually install everything so it could be self-contained in a version control repository that won't require additional installs. I've looked at the setup.py file but can't determine how it achieves the installation. – Soviut Oct 25 at 10:06
Why not use virtualenv to achieve this? You can push your env to source control as well, although that's not normal usage.
See: http://www.virtualenv.org/en/latest/