Module pyaxidraw not found even though it's in site-packages - python

I tried to connect to my pen plotter using package pyaxidraw. I did install it successfully, upgraded as it says on their site by using commands:
python -m pip install https://cdn.evilmadscientist.com/dl/ad/public/AxiDraw_API.zip
python -m pip install https://cdn.evilmadscientist.com/dl/ad/public/AxiDraw_API.zip --upgrade --upgrade-strategy eager
It is visible in site-packages folder, the files are there. However, I cannot import it in my scripts - I get ModuleNotFoundError: No module named 'pyaxidraw'.
Path to site-packages is added to Path variable, as are many other paths to python. Tried installing it through python setup.py install and pip install . and nothing changed.
I also tried running the code below and it does work fine through terminal:
python -c "from pyaxidraw import axidraw; ad = axidraw.AxiDraw(); print(type(ad)); ad.interactive(); ad.connect(); ad.moveto(3, 5); ad.lineto(0, 0); ad.disconnect();"
this makes my plotter move and plot just fine while in code it's still underlined in red because I can't import it.
But running the same code with "python3" instead of "python" in terminal gives me ModuleNotFoundError: No module named 'axidrawinternal'. It is said to work with Python 3.6 so I don't get what is happening.
How do I make python/Pycharm see this module so I can write scripts with it?

Related

ModuleNotFoundError: No module named 'schedule'

I have python program that imports schedule (import schedule) at the beginning. The code executes without a problem with python3 command, but starting it from other python file with call("sudo python3 ProgramWithSchedule.py", shell=True) returns error ModuleNotFoundError: No module named 'schedule'. And I can't figure out why...
I have library schedule installed with pip, pip3 AND apt-get (tried all three just to be sure :)
Thanks!
Because you are using a different interpreter/virtual environment for each project, which is generally considered the best practice.
You can apply the command below to create a file with all your installed modules, so you can use them whenever you want, by a single command to install all.
To keep/save all modules in a file:
pip freeze > requirements.txt
To install all of them with a single command in a new interpreter/virtual environment:
pip install requirements.txt
In case you tried installing a package and get an output:>>Requirement already satisfied.
You will find a path in your output where it says Requirement already satisfied, copy the path. Now go back to your working environment.
import sys
sys.path.append("/the/path/you/copied")
import schedule
You can try to force the usage of the same python interpreter with :
call(f"sudo {os.getenv('PYTHON3')} ProgramWithSchedule.py", shell=True)
and call your-script.py with :
PYTHON3=$(type python3) your-script.py ...

Package installed but doesn't import package

For some odd reason no matter which package I install when I go to import it doesn't know what package I'm talking about. I am very certain this is a Visual Studio Code error but if not I am also using Linux.
When I pip install the package pyttsx3 this is what I get in the Terminal:
Collecting pyttsx3
Downloading https://files.pythonhosted.org/packages/24/4e/580726c73272344d3e74b7aaffae55ff6b6450061fbecb8cc6e112531c02/pyttsx3-2.7.tar.gz
Building wheels for collected packages: pyttsx3
Running setup.py bdist_wheel for pyttsx3 ... done
Stored in directory: /home/secretlloyd/.cache/pip/wheels/a2/8a/fe/11112aca9c89142c3a404bc67ef3393a7ad530da26639a05d4
Successfully built pyttsx3
Installing collected packages: pyttsx3
Successfully installed pyttsx3-2.7
But when I run a example I get this error:
Traceback (most recent call last):
File "/home/secretlloyd/Visual Studio Code/Python/Finished/Text Colors/finished.py", line 1, in <module>
import pyttsx3
ModuleNotFoundError: No module named 'pyttsx3'
You can use an virtual environment to install your libs. If you do that, each project will have its own scoped libs without affect your global libs.
How to use the virtual environment?
Enter the root folder of your project and then run the following commands on the bash:
$ py -m venv .env
$ source .env/Scripts/activate
After that you'll notice your bash will have a prefix like that (.env). Then you should install your libs:
(.env) $ pip install pyttsx3
In order to deactivate the virtual environment just run the following command:
(.env) $ deactivate
Setup VS Code Intellisense for Virtual Environment
If you're using VSCode you can set the correct python interpreter after setting up a virtual environment. Just follow the steps:
Open VSCode in your project
Press F1
Type: > python: select interpreter
Click on Enter path or find an existing interpreter
Click on Find
The navigate to .env > Scripts > python
3 possible cases:
The same thing happened to me when I did not notice I was using two Pythons at the same time one 2.7 and another one 3.6. Make sure to know where is your package being installed to the Python modules folder you really want to store it or in another one you did not know existed.
Your PATH might not be configured correctly, check out either if you are using Windows or Linux if your PATH variables are configured correctly. You can reset your configuration if you wish. (link= How to reload .bashrc settings without logging out and back in again?)
For some packages/libraries of Python the way of importing the library is different from the name you import it on your .py file. For example: You can install OpenCV library by [pip install OpenCV] but when importing it in a file you have to write [import cv2].
I hope you find this information helpful for your problem.

Why am I getting "ModuleNotFoundError: No module name "pyperclip"?

I'm receiving this error although it works fine in the idle shell?
I am currently working through the Automate The Boring Stuff book.
I tried to search for which directory it was saved to but when I reach c:\users\Jibby\appdata\local\programs\python the only thing in the python folder is a folder named mu.
Edit: Apologies for not going into more detail, I already have it installed > I get this message when I try to pip install it again "Requirement already satisfied: pyperclip in c:\users\jibby\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (1.8.2)"
It's just that when I try to run a batch file using an import pyperclip statement, it refuses to acknowledge that I have it installed. That's what I was trying to show in the Error Code photo by showing it imports fine in the IDLE shell but doesn't work when trying to run said batch file.
My error:
You have to install pyperclip from cmd with
pip install pyperclip
Be sure to read Appendix A for how to install third party modules (including pip)
try to type into the command promt:
"pip install pyperclip"
https://pypi.org/project/pyperclip/
Got it to work by typing in "py -m pip install pyperclip" into the command line.

I cannot import a python submodule after successful installation of the module

I am trying to install the python submodule ANCA in my mac, for which I have run the following:
pip install git+https://github.com/acadev/anca.git
getting the following:
.
.
.
Installing collected packages: anca
Running setup.py install for anca ... done
Successfully installed anca-0.1.5
I have miniconda installed in my computer, and I have checked that the module and its files and dependencies are correctly located in /usr/local/miniconda2/lib/python2.7/site-packages/anca
When I import anca in my notebook it does not give me any error, but if I try to import a submodule it gives me the following error:
from anca import IterativeMeansAlign
ImportError: cannot import name IterativeMeansAlign
It is the same with other submodules, but all of them are apparently well installed with all their files.
I have also tried to install the package using Git:
git clone https://github.com/acadev/anca.git
sudo python setup.py install
with the same result.
Note: 'locate' is not able to locate the module anca unlike the rest of the python modules although I can see all the files in the right location. It is the first time this happens to me.
Thanks a lot for your help,
any suggestion will be very appreciated.

Installing GDAL Python binding in Ubuntu to use as standalone module

I am trying to export a GeoTiff with Blender using the Blender Python API (based on Python 3), so I've decided to install GDAL on Ubuntu (14.04). What I would like is to get the module as a standalone folder that I could put in the modules directory of Blender (/home/user/.config/blender/2.73/scripts/modules).
The thing is I've run through several different problems trying to install GDAL. I've tried to install from source (for GDAL 2.0.0) here : Official PyPi Gdal
I ran sudo apt-get install libgdal-dev gdal-bin (I list it here because it may be important)
When I am in the extracted GDAL folder, using python setup.py build & python setup.py install, the library installs to /usr/local/lib/python2.7/dist-packages/osgeo. However, when I run python from command line, running from osgeo import osr returns ImportError: No module named _gdal
Following GDAL via pip , I used pip (pip install GDAL) to install the library, and the folder it went to was /usr/lib/python3/dist-packages/osgeo (using pip show ...). Again, running python3 and trying to import results in the same error. Of course, when I copy-paste each folder in the blender module directory, I get the same error in the Blender Python console.
So I decided to compile the sources using ./configure --with-python & make & make install in the source folder. I then copied the folder GDAL-x.x.x/build/lib.linux-x86_64-3.4/osgeo to the blender modules directory and got this time the error when importing : ImportError: /home/yvesu/.config/blender/2.73/scripts/modules/osgeo/_gdal.so: undefined symbol: _Py_ZeroStruct.
Trying to compile with python3 using python3 setup.py build returns the error error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
EDIT 1:
I think I've found the solution : I went to the directory swig/python (not found in a GDAL-1.11.0 folder but gdal-1.11.0 fodler, can't remember where I downloaded it from), ran python3 setup.py build & python3 setup.py install and could finally find the folder in /usr/local/lib/python3.4/dist-packages/GDAL-1.11.0-py3.4-linux-x86_64.egg/osgeo. When I put this osgeo folder oni the Blender modules directory, I was able to import osgeo in Blender. I will report if anything went wrong.
I think I've listed all my attempts at installing GDAL on Ubuntu. Can anyone point me in the right direction? Do you think it is even possible to install it as a standalone module, or do I need linked libraries through LD_LIBRARY_PATH?
Here is the solution I've found :
Download Gdal sources (v2.0.0 is the current stable release) from ftp://ftp.remotesensing.org/gdal/2.0.0/ or http://download.osgeo.org/gdal/2.0.0/ and untar
Go to the directory gdal2.0.0/swig/python
Run python3 setup.py build & python3 setup.py install
Finally find the module folder in, on Ubuntu : /usr/local/lib/python3.4/dist-packages/GDAL-2.0.0-py3.4-linux-x86_64.egg/osgeo
I can now use it in Blender (copying in the modules directory)

Categories