I'm using CocoTB to test my HDL design, but as I understand, it's possible to use it with python2.7 or python3.
In setup.py config file I can see that both are supported :
[...]
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
[...]
In endian_swapper test (examples/endian_swapper/tests/test_endian_swapper.py), if I modify a test script to see which version is used :
#cocotb.test()
def wavedrom_test(dut):
"""
Generate a JSON wavedrom diagram of a trace and save it to wavedrom.json
"""
print("Python version used {}".format(sys.version_info))
I can see that python2.7 is used when I launch test with «make» command :
Python version used sys.version_info(major=2, minor=7, micro=9, releaselevel='final', serial=0)
My python3 executable is named ... python3 in fact (debian). Is there a canonical way to force cocotb to use python3 instead of python2 ?
try updating the PATH variable. worked for me.
when cocotb looks for python, it looks for it at the folders that are listed at the PATH variable.
let say that your python3 full path is at/usr/bin/python3
(you can find python3 full path by which python3)
i also added here link to new place in case both python2 and python3 are at the same folder...
> python -V
Python 2.7.17
> ln -s /usr/bin/python3 /home/$USER/python
> export PATH="/home/$USER:$PATH"
> python -V
Python 3.6.9
I found a proper way to do it.
First download the last version of python on the official website :
$ wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tar.xz
Then unflat it and configure it with the option --enable-shared
$ tar -Jxvf Python-3.7.4.tar.xz
$ cd Python-3.7.4
$ ./configure --enable-shared
$ make
$ sudo make install
Once installed go to your cocotb test directory then install virtual environment :
$ export LD_LIBRARY_PATH=/usr/local/lib
$ virtualenv --python=/usr/local/bin/python3.7 envp37
$ source envp37/bin/activate
$ python -m pip install cocotb
Then you can launch your cocotb test environment with traditional make :
$ make
Dectivate the python environment with :
$ deactivate
I found solutions on linuxconfig.org, thanks to themperek. But it's not exactly what I want.
The alias solution doesn't work for me. The update-alternative works but only with «official» python3 installed on debian. I can't use an alternative (3.7) manually installed.
$ sudo update-alternatives --config python
There are 3 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python3.7 2 auto mode
1 /usr/bin/python2.7 0 manual mode
2 /usr/bin/python3.4 1 manual mode
* 3 /usr/bin/python3.7 2 manual mode
Press enter to keep the current choice[*], or type selection number: 3
$ make clean;make
0.00ns INFO Running on Icarus Verilog version 11.0 (devel)
0.00ns INFO Python interpreter initialised and cocotb loaded!
0.00ns INFO Running tests with Cocotb v1.0.1 from /opt/cocotb
0.00ns INFO Seeding Python random module with 1554105931
0.00ns INFO Found test test_ttl.ttl_test
0.00ns INFO Running test 1/1: ttl_test
0.00ns INFO Starting test: "ttl_test"
Description: simple ttl test function
[...]
3.4.2 (default, Feb 7 2019, 06:11:23)
[...]
Related
I am not able to I have tried to install different version of python3.9.X (3.9.8, 3.9.9, 3.9.10, 3.9.11) and none of them are working.
I have also tried some 3.8.X and 3.5.X all giving different errors.
I will post the 3.9.8 log (the one I am interested on)
Platform information: MacOS Monterey 12.3.1
pyenv version: 2.2.5
Python version: 3.9.8
C Compiler information: Apple clang version 12.0.5 (clang-1205.0.22.9)
Command used in pyenv: pyenv install 3.9.8
This is my .zprofile (I am using oh-my-zsh)
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
I have also installed all the required dependencies
brew install openssl readline sqlite3 xz zlib
Here you can find the log and here you can find the config log
This is what I am getting:
# pyenv install 3.9.8
python-build: use openssl#1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.9.8.tar.xz...
-> https://www.python.org/ftp/python/3.9.8/Python-3.9.8.tar.xz
Installing Python-3.9.8...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
BUILD FAILED (OS X 12.2.1 using python-build 20180424)
Inspect or clean up the working tree at /var/folders/jl/hp_s9knj13x5ft7mffr258r40000gp/T/python-build.20220412182145.25030
Results logged to /var/folders/jl/hp_s9knj13x5ft7mffr258r40000gp/T/python-build.20220412182145.25030.log
Last 10 log lines:
if test $? -ne 0 ; then \
echo "generate-posix-vars failed" ; \
rm -f ./pybuilddir.txt ; \
exit 1 ; \
fi
make: *** [Makefile:688: python.exe-gdb.py] Killed: 9
make: *** Waiting for unfinished jobs....
/bin/sh: line 5: 33970 Killed: 9 ./python.exe -E -S -m sysconfig --generate-posix-vars
generate-posix-vars failed
make: *** [Makefile:618: pybuilddir.txt] Error 1
I spent a couple of days with the issue and I found the answer on the GitHub Issues.
The problem was the antivirus as documented here.
Once the Antivirus was disabled everything was installed without any error (I tried python 3.9.8, 3.9.9, 3.9.10, 3.9.11). I had Apex One (Mac) Antivirus and uninstalling was not trivial.
This guide was helpful. I used Those two commands:
sudo launchctl unload /Library/LaunchDaemons/com.trendmicro.* /Library/LaunchAgents/com.trendmicro.*
sudo kill -9 $(pgrep iCoreService TmLoginMgr)
If you recieve this warning is completly fine
Warning: Expecting a LaunchDaemons path since the command was ran as root. Got LaunchAgents instead.
`launchctl bootout` is a recommended alternative.
/Library/LaunchAgents/com.trendmicro.TmLoginMgr.plist: Could not find specified service
Unload failed: 113: Could not find specified service
Just check your Icon on the top bar is gone. Additionally you can make sure this command does not return any process:
pgrep iCoreService TmLoginMgr MainUI
I am facing a strange problem which I could track down to the python logging package. Let me shortly explain what I want to do: the goal is to create html reports with python. I am using the R rmarkdown package which runs python code trough reticulate using a local virtualenv.
The Problem:
As soon as I install the python logging package rmarkdown runs into a problem when loading matplotlib. I have written a small test script to reproduce the example.
My system:
Ubuntu 18.04 bionic
Python 2.7.15rc1
Test "1" script (without logging):
Create a new virtualenv (venv).
Use venv/bin/pip to install matplotlib.
Run reticulate::import (at the end via rmarkdown::render).
Test "2" script (with logging):
Create a new virtualenv (venv).
In addition to the first test: install logging via venv/bin/pip.
Use venv/bin/pip to install matplotlib.
Run reticulate::import (at the end via rmarkdown::render).
The modules installed (virtualenv):
backports.functools-lru-cache 1.5
cycler 0.10.0
kiwisolver 1.0.1
logging 0.4.9.6 <- only for "test 2"
matplotlib 2.2.3
numpy 1.15.1
pip 18.0
pkg-resources 0.0.0
pyparsing 2.2.0
python-dateutil 2.7.3
pytz 2018.5
setuptools 40.2.0
six 1.11.0
subprocess32 3.5.2
wheel 0.31.1
The system site packages do have the same module version.
Results:
All tests from test 1 (without logging) work nicely.
The tests from test 2 (with loging) fail when using the virtualenv. When calling rmarkdown::render (see below), when using the system python installation (not virtualenv) they work nice as well.
There seem to be something strange with reticulate when logging is installed in a virtualenenv.
The output of the test script (see below):
The full output including the error:
----------- no logging package installed ------------
Module(matplotlib)
Module(matplotlib)
--------- with logging package installed ------------
Error in py_module_import(module, convert = convert) :
AttributeError: 'module' object has no attribute 'NullHandler'
Detailed traceback:
File "/home/retos/Downloads/venvtest/venv/lib/python2.7/site-packages/matplotlib/__init__.py", line 168, in <module>
_log.addHandler(logging.NullHandler())
Calls: <Anonymous> -> py_module_import -> .Call
Execution halted
Module(matplotlib)
The Module(matplotlib) output is the success message of loading the module via reticulate::import. As one can see only the one test fails where the virtualenv is used with installed logging python module.
Anyone having an idea what could case these problems? I spent quite some time to identify the source of the error, but I am kind of lost now ...
Test script to reproduce the error:
Here is a small bash/shell script to reproduce my tests.
#!/bin/bash
# New virtual environment and install matplotlib
echo " ----------- no logging package installed ------------"
if [ -d venv ] ; then rm -rf venv ; fi
virtualenv venv &>/dev/null > /dev/null
venv/bin/pip install matplotlib > /dev/null
# Print installed packages
Rscript -e "reticulate::use_python('venv/bin/python'); reticulate::import('matplotlib')"
Rscript -e "reticulate::import('matplotlib')"
# New virtual environment and install logging and matplotlib
echo " --------- with logging package installed ------------"
if [ -d venv ] ; then rm -rf venv ; fi
virtualenv venv > /dev/null
venv/bin/pip install logging > /dev/null
venv/bin/pip install matplotlib > /dev/null
# Print installed packages
Rscript -e "reticulate::use_python('venv/bin/python'); reticulate::import('matplotlib')"
Rscript -e "reticulate::import('matplotlib')"
I first thought it is related to the problem "ImportError: cannot import name cbook" but the solution there did not work.
May thanks in advance!
R
Logging became a standard module included in Python library in version 2.3. You must not install it from PyPI. Remove it ASAP:
pip uninstall logging
I am installing Hyperledger Indy (sovrin) self-identity software per these instructions.
I have Python2.7 installed via Anaconda 3. I also have Python3.6.3 installed that I downloaded and installed from here.
I'm trying to install some other software that has a dependency for Python > 3.5.
I've tried several methods to change my default Python:
Per this SO I set it manual in current terminal window:
alias python='python3'
Per same SO I vi .bash_profile and added:
alias python='python3'
then source ~/.bash_profile
Set a link to Python3:
bc-computer:~ momi$ unlink /usr/local/bin/python2
bc-computer:~ momi$ ln -s /usr/local/bin/python3 /usr/local/bin/python
but still continue to get the same error:
bc-computer:~ momi$ pip install indy-node-dev
Collecting indy-node-dev
Using cached indy-node-dev-1.2.227.tar.gz
Complete output from command python setup.py egg_info:
FAIL: Requires Python 3.5 or later, but setup.py was run using 2.7.14
NOTE: Installation failed. Run setup.py using python3
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/3f/sh6dr8wx6w720b1_w38f_fh00000gq/T/pip-build-ecZnYY/indy-node-dev/
I also tried setting up a python3 test environment per this:
python3 setup.py test
And got this error:
> /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python:
> can't open file 'setup.py': [Errno 2] No such file or directory
Please note that I tried this suggestion which seems to be the non-duplicate answer but didn't work for me:
The safest way is to set an alias in ~/.bashrc:
alias python=python3
My environment:
uname -msra
Darwin bc-computer.local 17.2.0 Darwin Kernel Version 17.2.0: Fri Sep 29 18:27:05 PDT 2017; root:xnu-4570.20.62~3/RELEASE_X86_64 x86_64
My OS:
High Sierra 10.13.1
which -a python
/Users/momi/anaconda2/bin/python
/usr/local/bin/python
/usr/bin/python
Thank you
Ok the solution was to use pip3 rather than pip for my install command per Mike Mueller's answer here:
pip3 install indy-node-dev
I assume that pip3 points to python3x rather than 2x.
I have also installed Hyperledger Indy SSI VC using MacOs Python 3.6.3. It is working for for me. I could demo the VON Network. It seems that your machine environment still points to Python 2.7. There are different ways by which we can point to Python 3.6.3 through virtual environment. You can try those options.
This question already has answers here:
Use different Python version with virtualenv
(41 answers)
Closed 6 years ago.
My default python version on my Debian 8.5 machine is 3.4.2. I want to use python 2.7 for only one project. I have tried running all of the following commands in the terminal one by one, :
virtualenv -p python2.7 env_dir
virtualenv -p python2 env_dir
virtualenv --python=python2.7 env_dir
And this is the file.py inside the env_dir:
print "Hello world from inside env_dir"
Obviously however the file.py still gets executed with python3.4.2, because i run:
python file.py
and i get:
File "file.py", line 1
print "Hello world from inside env_dir"
^
SyntaxError: Missing parentheses in call to 'print'
What is the problem, why it fails to run the code in python2.7?
Update
I have also tried:
virtualenv -p /usr/bin/python2.7 env_dir
source env_dir/bin/activate
(env_dir) amir#amir-debian:~/env_dir$ python file.py
File "file.py", line 1
print "Insid virtual env"
^
SyntaxError: Missing parentheses in call to 'print'
Running python -V after activating returns: Python 3.4.2
Update-2
Here is the process how i try to create my virtualenv and the outputs from terminal:
$ virtualenv --python=/usr/bin/python2.7 venv3
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in /home/amir/Desktop/venv3/bin/python2.7
Also creating executable in /home/amir/Desktop/venv3/bin/python
Installing setuptools, pip, wheel...done.
$ source venv3/bin/activate
(venv3) amir#amir-debian:~/Desktop$ python -V
Python 3.4.2
(venv3) amir#amir-debian:~/Desktop$ python
Python 3.4.2 (default, Oct 8 2014, 10:45:20)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Why is the working version still 3.4.2 and not 2.7 as i gave as OPTION to vertualenv when creating venv3?
Check if you have python2 by doing python -v
if you do have it, you can do python2 file.py
There's also an answer from here
which is
virtualenv -p /usr/bin/python2.7 <path/to/new/virtualenv/>
You can specify the version of python to use by doing
$ virtualenv venv --python=/usr/bin/python2
(Step 1)
I'm trying to get openCV to run from python on my mac using the MacPorts install http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port, and also trying to follow The Petite Geek's guide:
sudo port -v install opencv +python26
It runs for about 10 minutes without errors.
(Step 2)
I download ctypes-opencv source and demo files. I navigate to the src directory and run:
sudo python setup.py install
I see like 50 lines almost all of the form: copying ... -> ..., which looks good to me. No errors here.
(Step 3)
I add export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib to the end of my ~/.profile.
(Step 4)
I open a new terminal to test my install. From my home folder:
$ python
Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv
>>>
Does not work.
I read somewhere that opencv installs python bindings with the default version of python for OSX, and I am probably running a non-default version, but this is not actionable information to me.
I struggled for a while with Python on Mac. Here is how I finally (and easily!) installed it. Remove all the things Python you have on there already. They will probably be located at /Library/Frameworks/Python.Framework and /opt/local/var/macports/software/py26*
First download Python with Macports.
sudo port install python27
Then make sure your system is using this version with:
sudo port select --set python python27
Next install numpy with:
sudo port install py27-numpy
Now install opencv:
sudo port install opencv +python27
Now edit your ~/.bash_profile with:
sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit ~/.bash_profile
or
open -t ~/.bash_profile
and add the line:
export PYTHONPATH=/opt/local/var/macports/software/opencv/2.2.0_0+python27/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages:$PYTHONPATH
or where ever your version of the cv.so file is hidden....
Now restart terminal and try:
%python
>>>import cv
I'm using Netbeans for opencv and python and it works really nice. Good luck.
$ brew search opencv
homebrew/science/opencv
$ brew install homebrew/science/opencv
after installed, there is warning:
==> Caveats
If you need Python to find the installed site-packages:
mkdir -p ~/Library/Python/2.7/lib/python/site-packages
echo '/usr/local/lib/python2.7/site-packages' > ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth
so, just do
mkdir -p ~/Library/Python/2.7/lib/python/site-packages
echo '/usr/local/lib/python2.7/site-packages' > ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth
If you notice the first line output when running python, you'll see that you're still using the Apple-supplied Python interpreter. Try installing and using the python-select package in MacPorts and then try the instructions again starting from step 2.
Also make sure you followed all of the steps when installing MacPorts so that /usr/local/bin is on $PATH.
Another "hack" I found during my struggles using CMake (but maybe the problem is the same with ports) : it appears that the python modules location has been duplicated on my Mac OS Lion, for a reason I can't explain.
CMake wants to put the "cv" module here :
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Whereas my default Python interpreter is looking here (thanks PyCharm for telling me) :
/Library/Python/2.7/site-packages
Moving both cv2.so and cv.py files to the second location, did the trick for me. I don't know if this is the cleanest way.
Hope it can help some googlers !