在python脚本中安装没有pip的模块

时间:2018-08-15 16:14:53

标签: python pip install testcomplete

我在没有点(测试完成)的独立环境中使用AnyTree。

我首先将Anytree文件夹移动到所需的文件夹,然后开始出现六个导入错误。我下载了六个文件,并将其放入其中,现在我得到了:

'module' object has no attribute 'iterator'

如果有人感兴趣-这是无需点子即可执行此操作的代码:

from os import sys


sys.path.insert(0, "C:\Program Files (x86)\SmartBear\TestComplete 12\Bin\Extensions\Python\Python34\Lib\site-packages")

import six
import anytree

udo = anytree.Node("Udo")
print(udo)

关于如何解决此问题的任何想法? Google只返回了以下结果:__builtin__.iterator does not exist?

我唯一能想到的两个选择是-物理移动文件夹(尝试过但出现上述错误)或通过脚本安装:

它似乎也不起作用(在2.7上,而我在3.6上尝试了更新的脚本,但均无效)。

import sys
import os
import site 
from importlib import reload

try:
   import pip
except ImportError:
   print "installing pip"
   cmd = "sudo easy_install pip"
   os.system(cmd)
   reload(site)

try: 
   import requests
except ImportError:
   print "no lib requests"
   import pip
   cmd = "sudo pip install requests"
   print "Requests package is missing\nPlease enter root password to install required package"
   os.system(cmd)
   reload(site)

1 个答案:

答案 0 :(得分:1)

我之前写过类似的文章,而您走在正确的道路上。代替

export class UserBookingsComponent implements OnInit {
  isLoading = false;
  isDisabled = false;

  displayedColumns: string[] = [
    'date_of_booking',
    'booked_date',
    'booked_time',
    'coach',
    'cancel_booking'
  ];
  dataSource: MatTableDataSource<any>;

  bookings: Booking[] = [];
  userId: number;
  disableBookingId: number;
  nowDate = moment().format('YYYY-MM-DD');

  @ViewChild(MatPaginator) paginator: MatPaginator;
  @ViewChild(MatSort) sort: MatSort;

  constructor(
    private _authService: AuthService,
    private _userService: UserService,
    private _coachService: CoachService,
    private _route: ActivatedRoute,
    private _router: Router
  ) {}

  ngOnInit() {
    this.userId = this._authService.getUserId();
    this.isLoading = true;

    this._userService.getUserBookings(this.userId).subscribe(bookings => {
      bookings.forEach(booking => {
        if (moment(booking.booked_date).isBefore(this.nowDate)) {
          console.log(booking.id);
          this.disableBookingId = booking.id;
        }
      });
      this.dataSource = new MatTableDataSource(bookings);
      this.dataSource.paginator = this.paginator;
      this.dataSource.sort = this.sort;
      // this.bookings = bookings;
      this.isLoading = false;
    });
  }

  applyFilter(filterValue: string) {
    this.dataSource.filter = filterValue.trim().toLowerCase();

    if (this.dataSource.paginator) {
      this.dataSource.paginator.firstPage();
    }
  }
}

您需要尝试

cmd = "sudo easy_install pip"

并指向您可以在此处Very simple log4j2 XML configuration file using Console and File appender 下载的文件。

此外,您可以在Windows的命令行中运行pip,而无需在python终端中运行。像这样:

cmd = "get-pip.py"